How can create a TV on for a ressource

Hello
I would like to create a Template Variable and I provide access to my template.
I can see the TV in all ressources but I would like allowed only for one ressource.

The goal is the create an accordeon content. Each TV will contain the texte which will be collapse or not following the first h4, in the TV. I need about 7 TV for a ressource.

I might need to create a new accordeon for another ressource. That the reason why, I would like to make sure, the TV will be sown only for the selected ressource.

Is possible to grant access to the TV, not only to the template, but for a selected resspurces as well?

Many thank for your suggestion

Cheers

Another idea, would be to create a new template, which will be the clone of the ‘Pages’ template. Then I can apply the new template to one ressources, but I do not really like it, because if I make a change the the ‘Pages’ template, I do not have to forget to make the change to the new template, as well…

Or would it be possible to create. anew template, which will inherit from the ‘Pages’ template?

Maybe you could create a chunk that both of your templates use. A change to the chunk would then affect both templates.

Also, maybe it is easier to use MIGX than to create 7 different TVs.

You could also do this with child pages of the resource that will have the accordion, instead of template variables. And then use a pdoResources or getResources or maybe getfield snippet to call the contents of the child pages into the accordion of the parent page.

The advantage would be the flexibility in being able to add or remove the number of child pages, and easily reorder them. The template for the child pages can be whatever you need, or empty. For instance with no template for the child pages you can utilize the existing fields; perhaps the *longtitle to populate the link text of the accordion and *content for the text to reveal.

Then do the same for any other resources that will have their own accordion section.

Dear Lucy,
That’s very interretsing.
For now I installed getRessource.
I created two child ressource of thge ressource with the id 33
I created a chunck named Accordeon33 where I pasted

<div>
[[getResources? &parents=`33`]]
</div>

In my resource 33, I called the chunck
[[$Arccordeon33]]

I refersh my page and I have an empty line. I am agree that’s not the final solution, but should I get someting printed, isn’t

you will need a &tpl property and a tpl-chunk, where you define the output for each resource in the listing

Ok that’s help a lot, thank

I created 9 child ressources of resource 33

Then I changed to

<div class="accordeon">
[[getResources? &parents=`33` &resources=`41,42,43,44,45,46` &tpl=`accordeonTpl` &includeContent=`1` &sortby=`{"id":"ASC"}`]]
</div>

then I created accordeonTpl

<h4>[[+pagetitle]]</h4>
[[+content]]

I am very happy with the result, but I saw some problem.

First only the first 6 child ressource are shown.
If I unpublish the 5th child ressource (the goal was to six if the 6th child is shown whild the 5ft is unpublished), the unpublished child are still shown.

I wonder why the only the 5th first child are shown and not all of the 9 childs and how hidden the unpublished?

Thanks a lot
Cheers

Yes, What Bruno says, or just use an inline template.
Snippet:

[[getResources? 
    &parents=`[[*id]]` 
    &includeContent=`1` 
    &tplWrapper=`@INLINE <ul>[[+output]]</ul>` 
    &tpl=`@INLINE <li>[[+content]]</li>`
]]

The above assumes you want to grab the content from the child pages of parent page, print each as a li, all wrapped in a ul. Change the HTML to whatever you need for your accordion markup.
If you’re not using the content field, and instead using a TV, you need to use the includeTVs property, and possibly others. Read more about getResources in the docs.

You would put the above snippet call in a chunk called myChunk for instance, and then call the chunk in your page template with a conditional.
Something like:

[[[[*id:is=`27`:then=`$myChunk`:else=``]]]]

(Change 27 to your parent page ID.)

1 Like

5 is the default for the &limit property.
You would do well to stop and carefully read the docs now. getResources is very flexible and configurable and you need to know all the defaults.

1 Like

Dear lucy and all
Thanls a lot. That works fine in a chunck

[[getResources? 
    &parents=`[[*id]]` 
    &includeContent=`1` 
    &tplWrapper=`@INLINE <div class="accordeon">[[+output]]</div>` 
    &tpl=`@INLINE <h4>[[+pagetitle]]</h4>[[+content]]`
	&sortby=`{"id":"ASC"}`
	&limit=`0`
	&showUnpublished=`0`
	&showHidden=`1`
]]
1 Like

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.