We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43280
    • 15 Posts
    Hello, Im trying to figure out how to use a dropdown list (single selection) TV to control what TPL is used with a blogpost.

    What I have is a simple blog setup, but blog posts are to be shown on the "Home page" with special formatting depending on the post type. So for example if the post type is "multimedia" it needs to use a different "rowTPL" than if the post type is "text".

    I understand how to use getResources to output new blog posts on the frontpage but I'm unsure how to format the getResources call to retrieve the TV "post type" info and then choose the TPL based on that. Any help is sure appreciated!

    EDIT: i have done some digging, and it appears that i can use getResources' "conditionalTPLs" property to acheive this

    (i saw it in this thread https://forums.modx.com/thread/77711/getresources---different-template-for-each-resource)

    So i guess now that all i need to do now is figure the correct syntax for this property in my get resource call; that is how to get it to check for the tv value chosen, and then assign a specific TPL for each possible TV choice. will be trying whatever i can but any help would be great; Im still a little dumb to more advanced stuff like this. however if i figure it out i will be sure to post my solution.

    EDIT 2: upon further research, the conditionalTpls property has to be a resource field and cannot be a TV. hmmm not quite sure how to pull this off as of now, there may be a different approach that needs to be taken.

    This question has been answered by sottwell. See the first response.

    [ed. note: wonderfulweb last edited this post 12 years, 5 months ago.]
    • discuss.answer
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Could you put a classname in your tpl that is populated by the TV value, then use CSS to modify the styling of the blocks?
      <article class="[[+tv.post-type]]">...</article>
      
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 43280
        • 15 Posts
        Quote from: sottwell at Apr 18, 2014, 10:03 PM
        Could you put a classname in your tpl that is populated by the TV value, then use CSS to modify the styling of the blocks?
        <article class="[[+tv.post-type]]">...</article>
        

        First let me say thank you so much! I guess i got so flustered that it never crossed my mind that this could be a possible solution!

        In my situation this will completely resolve my issue. I was concerned because the post types include a specific icon bundled in with an icon font set (using the great FontAwesome) that is typically called with an (arbitrary) html tag but this can be bypassed using css:before/after . If for some reason I *had* to have separate html code i guess this "pure css" solution wouldn't fit (theres javascript for that i guess) but I'll cross that bridge whenever i find myself there.

        Thanks again for the help


        Edit: just for the sake of anyone possible encountering a similar issue, There is another way to go about this as well. if you make a single tpl that consists of [[$[[+tv.post-type]]]] , then the tv is evaluated first, and then the chunk. so it would work basically the same as css class but with chunks instead, allowing you to make html changes as well as css. [ed. note: wonderfulweb last edited this post 12 years, 5 months ago.]