Forum

Thread tagged as: Question

Create custom content without a template?

Hi, I have a field that just contains some text. It's just a one-off field for one page, with not much complex markup around it (just inside a paragraph tag). So I'd prefer not to have my markup spread out between my php page and a separate file in /perch/templates/content/... rather, I just want to be able to declare that a certain content region contains certain fields. In my php file I am using perch_content_custom() with the 'skip-template' option to retrieve that data in raw form, so I'm wondering if I can also define the field itself in "raw form" (without a template file, because the template file only has 1 line of code in it for the perch:content tag).

Right now my php page has this:

<p>
    <?php
    perch_content_create('My Text', array(
        'template' => 'my_text.html',
        'multiple' => false,
        'edit-mode' => 'singlepage',
    ));
    $my_text = perch_content_custom('My Text', array(
        'template' => 'my_text.html',
        'skip-template' => true,
        'return-html' => false,
        'raw' => true,
    ));
    echo $my_text;
    ?>
</p>

And this requires that I also have a /perch/templates/content/my_text.html file with a dummy field in it, really just to declare the field as being "textarea" type:

<perch:content id="my_text" type="textarea" label="My Text" />

Is there a way to achieve this by just defining the field as part of the perch_content_create function (or some other way)? Or do I really need to have these one-line files in my templates folder (far away from the php page where they're being used)?

Thanks.

Web Concentrate

Web Concentrate 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Templates are used for defining the way content is captured as well as how it's output. So you always need a template - even if it's just a simple one.

If it's just a one-liner, it shouldn't much problem to set-and-forget. Should you want to change the options in the future (like adding an editor, changing the input size, anything like that) you've got it all conveniently in one place rather than having to update every instance.

Typically we wouldn't see templates as simplistic as your example, so it does feel like overkill when normally it wouldn't.