Forum

Thread tagged as: Question

Set Label using System Variable

Is it possible to set the label of a content template in the admin area using a system variable? Eg.

<perch:if exists="dynamicLabel">
    <perch:content type="textarea" id="pageContent" label="<perch:content id='dynamicLabel'/>" html="true" editor="ckeditor" />
 <perch:else />
     <perch:content type="textarea" id="pageContent" label="Text" html="true" editor="ckeditor" />
</perch:if>

The if statement works fine, however the label reads "<perch:content id=" and the editor plugin doesn't load.

Not a huge problem if it's not possible, I want to re-use the same template in different scenarios - I just don't want to call every text block "Text".

Tony Astley

Tony Astley 0 points

  • 3 years ago

Add : title=“true” to perch:content tag of the content you want to show as a label in admin listing.

I'm not sure that's the same thing? I want to pass the label name from the php master page into the template:

eg to change the default text block label from 'Text' to 'About You'.

Creating the region in the PHP master page:

PerchSystem::set_var('dynamicLabel', 'About You');
    perch_content_create('About You', array(
        'template' => 'intro.html',
    ));

Then having the intro.html content template pick up the name to show in the admin area:

<perch:if exists="dynamicLabel"> <perch:content type="textarea" id="pageContent" label="<perch:content id='dynamicLabel'/>" html="true" editor="ckeditor" /> <perch:else /> <perch:content type="textarea" id="pageContent" label="Text" html="true" editor="ckeditor" /> </perch:if>

I could hard code the target result:

<perch:content type="textarea" id="pageContent" label="About You" html="true" editor="ckeditor" />

However this would result in multiple templates each with their own label negating the benefit of being able to nest them.

If you look in the documentation that shows how to pass variables into templates.

I'm on top of the method, what I want to know is if variables can be parsed by the admin views in the same way the front end views do?

I'm guessing they cannot?

Drew McLellan

Drew McLellan 2638 points
Perch Support

They cannot.

Thanks Drew.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

The Region's name is listed at the top of the edit form. So while you can't change the label dynamically, at least the Region's name can be more meaningful than "Text".

It's not the region Hussein, it's the label of the content within the region.

No problem, just would be a nice feature.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Yeah, I get what you're trying to do. All I'm saying is the name of the region is listed in the edit form which is better than nothing.

A region named 'About me' and a region named 'Intro' can use the same template and the fields in both edit forms would be labelled identically, but at the top of the edit form the editor can see the name of the region they are editing.

Yeah, I used to do it that way, but ended up with lots of regions.

I try to keep the number of regions down to make editing more streamlined. I then re-use the content with different templates.

Thanks for looking at it though.