Is possible to limit the Template Variable for a type of resources


I have a parent page and subpage. The subpage inherit the template from its parent.

_ Teachers
__ teacher
__ teacher

For the teacher pages, I added 3 template variables (picture, phone and e-mail)
But the TV is available for the Ecole and teachers resource and I would like to have them only for the teacher resources

Is it possible and how to have the TV available only for the teacher resource without creating a template specialy for the reacher resources?

Thanks for your help

I think your only option may be manipulating the page content through a Plugin.

You could take a look at @halftrainedharry response here as a starting point

You should be able to hide them by using a different template for the ecole and teachers pages. It can be an exact duplicate for the one for the teacher pages (or not). Just don’t connect the TVs to the template(s) of the pages where you don’t want them to appear.

@bobray It’s what I prefer to avoid :slight_smile:

Is it possible to create a template with a basic html code and then in my school template, include it?

For exemple in my school template, I have this



		  &then=`<a href="[[~9]]" class="retour" title="retour">&#60;&#60; RETOUR ADMINISTRATION / PROFESSEURS</a>`

As the [[if] concern my profile page, I could remove it, and include in my profile template.
Would it possible to do that, so how


In that case, I will have to create a new template, but all my sub resource will ingerit the template of the parent. It’s a point important, because while the use will create a new profile, he/she will not need to have an attention to choose the correct template and then avoid errors,

I would do that with a Chunk rather than a Template:


or (uncached if the chunk changes often)


Hello @bobray
yes, but I can not assign a TV to a chunck, isn’t?
The goal is to assign a TV only for the profile page.
The idea is to include the profile template to the school template only for some subresources (which are the profiles)

Are we talking about the Manager or the front end of the site?

I really would avoid conditionals like that and just use two different templates.
You could have a plugin, which would set the right template, while creating new resources.

If you don’t want duplicate your template code, you can put the whole template code into a chunk and call that chunk in your template.

Then pass the variable parts like that:

Template 1:

&specialpart02=`<a href="[[~9]]" class="retour" title="retour">&#60;&#60; RETOUR ADMINISTRATION / PROFESSEURS</a>`

Template 2:


then use it like that in your templateChunk:


Bruno17’s suggestion is very good. Here’s another option:

I said I would use a chunk, but on second thought, I would use a custom snippet with this tag in the template:


BioData Snippet:

/* BioData snippet */
$output = '';
$parentId = $modx->resource->get('id');

if ($parentId == 12) { // change 12 to Id of Teachers page
    $output =  '

return $output;

You could speed this up a little by calling $modx->resource->getTVValue('TVName) for each value, but I’m not sure it’s worth the trouble.

Maybe you could use the extra Collections for this.
If you make the resource “Teachers” a collection, you can specify the default template for all newly created child resources.

An alternative would be a plugin attached to OnDocFormSave that automatically sets the template for the teacher pages:

/* TeacherTemplate plugin */
$teachersId = 12;  /* Change to ID of the Teachers page*/
$desiredTemplate = 22; /* change to ID of the Template you want for teacher pages. */

/* Only execute for new resources */
if ($mode !== modSystemEvent::MODE_NEW) {
    return "";

$parent = (int) $resource->get('parent');

if ($parent !== $teachersId) {
    return "";  /* (not a teacher resource) */
} else { /* Set desired template */
    if ($resource->get('template') != $desiredTemplate) {
        $resource->set('template', $desiredTemplate);

Hello all
Thanks a lot for all of your replies. I have not had time to read but I will continue my work tomorrow, but I would like to thanks before tomrrow. All look veey interesting. Look forward tomorrow. Thanks

I just send you a feedback. I have not forgotten to reply to your suggestion but I have to complete the forms of my MODx asap. When I will complete it, I will be back to work around that topic. Sorry for my delay

Take your time. I’ve got plenty to do. :wink:

1 Like