Hello all,
I am implementing a pattern that comes up pretty regularly for me, which is a sidebar where there are a number of positions at the side of a page where the content editor can choose what appears in each.
I am taking a different approach this time, and am looking for a second set or eyes to perhaps make the approach more elegant, but otherwise to fix a problem.
The sidebar content is contained in resources under a Sidebar parent in the resource tree. These just have a title and content defined.
Sidebar
- Sidebar-a
- Sidebar-b
- Sidebar-c
- Sidebar-etc
The sidebar content is flexible - could be anything,
The resources that support sidebars have three Resource TVs, which points to the Sidebar parent. So far so good, the content editor can select a sidebar resource via the TV. There are also three list-box TVs that define the class that will be used to style the sidebar element. So sidebar1 TV contains the resource to be displayed, and sidebar1-colour defines the class that styles it (red||green||blue for example).
The template contains this:
[[*sidebar1:notempty=`
[[!getResources? &parents=`31` &resources=`[[*sidebar1]]` &tpl=`sidebarbox` &includeContent=`1`]]
`]]
[[*sidebar2:notempty=`
[[!getResources? &parents=`31` &resources=`[[*sidebar2]]` &tpl=`sidebarbox` &includeContent=`1`]]
`]]
[[*sidebar3:notempty=`
[[!getResources? &parents=`31` &resources=`[[*sidebar3]]` &tpl=`sidebarbox` &includeContent=`1`]]
`]]
Note that there is a single template for displaying the sidebar elements, and it looks like this:
<div id="red-box">
<div class="header">[[+longtitle]]</div>
<div class="content">[[+content]]</div>
</div>
Now rather than only having one template per colour and hardcoding the id, I want to use the sidebar1-colour - like this:
<div id="[[*sidebar1-colour]]-box">
<div class="header">[[+longtitle]]</div>
<div class="content">[[+content]]</div>
</div>
The problem here is that that this can't work for all three sidebars without a separate template again.
It would need to look something like:
<div id="[[*sidebar[[+sidebarid]]-colour]]-box">
<div class="header">[[+longtitle]]</div>
<div class="content">[[+content]]</div>
</div>
And then get sidebarid somehow passed through from getResources. I can't think of a way of doing this...
I know I could create a custom snippet and solve this fairly easily, however I wanted to see if I could get an out-of -the-box solution with just standard modx components.
Any suggestions would be welcome - sometimes with modx you need to think differently and I get the feeling I am missing a simpler approach.
Cheers,
Paul
[ed. note: paulkoan last edited this post 15 years, 1 month ago.]