Articles use different "rowTpl" chunk depending on post

I have a blog using Articles and I have the usual (text based) posts which are shown on the blog page through a rowTpl. This contains the articles title, an image, author, teaser text, etc. and of course a link to view the whole post.

rowTpl
<article class="post style2">
   <div class="content">

      <header>
         <span class="category">by <a href="[[~[[*id]]]]author/[[+createdby:userinfo=`username`]]">[[+createdby:userinfo=`username`]]</a> on [[+publishedon:strtotime:date=`%b %d, %Y`]] [[+tv.articlestags:notempty=` | [[%articles.tags]]: [[!tolinks? &items=`[[+tv.articlestags]]` &target=`[[*id]]` &useTagsFurl=`1`]]`]]</span>
         <h3><a href="[[~[[+id]]]]">[[+pagetitle]]</a></h3>
      </header>

      [[+introtext:default=`[[+content:ellipsis=`200`]]`]]

      <ul class="actions">
         <li><a href="[[~[[+id]]]]" class="button next">Read More</a></li>
      </ul>

   </div>
   <div class="image" data-position="center"><img src="[[+tv.article-img]]" alt="" /></div>
</article>

Now I also want to display videos within the same blog feed but obviously without a teaser text for example. Ideally I would embed the video, so it can be viewed from this page directly and there’s no need to click any further to watch the video. Therefore I would like to use a different rowTpl for the video posts.

I know I can assign every post itself to a unique template but I don’t seem to be able to distinguish that on the blogs feed. My question therefore is: How can I display blogs and videos within the same feed but using different container templates?

Important is, that the videos should be created as an articles resource, so all the contents of the blog (posts and videos) are chronological sorted and accessed through the same thing.

My approach so far is that I could assign a video tag to all video posts but then again I don’t know how I would go about showing them differently in the feed. Any ideas?

Depending in where you are in the build of the site maybe you could consider retrieving the articles rather than displaying them direct. This might give you more flexibility: https://docs.modx.com/extras/revo/articles/articles.retrieving-articles-outside-of-articles

I’ve seen that, but I don’t think it solves my issue. The way I see this I could retrieve either videos or posts within a certain template but I need both within the same feed but using different templates. This could be an example feed:

  • Text Post #1 (using blog template)
  • Text Post #2 (using blog template)
  • Video Post #1 (using video template)
  • Text Post #3 (using blog template)
  • Video Post #2 (using video template)
  • Text Post #4 (using blog template)

Maybe use output modifiers (filters)? Create a tv to hold the video. use the same rowTpl for all but check whether the tv.video is not empty. If it’s not empty, display it but don’t display the teaser, text, image or read more button?

&conditionalTpls should help
https://forums.modx.com/thread/77711/getresources---different-template-for-each-resource#dis-post-428974

1 Like

That’s a nice idea and I tried it by checking if the [[+tv.articlestags]] would contain my video-tag but unfortunately I did only receive the video post as output and nothing else. Also I think modifiers in this scenario would be quite slow.

That looks like a beatiful solution! Is there a way how I can integrate this without substituting the base [[+articles]] call (and therefore loosing all the settings made through the Articles resource)?

maybe it is possible to create a TV to set this additional properties and have a plugin at onDocFormSave, which would modify the advanced settings

@bruno17 can you go into a little more detail about what you mean exactly? I haven’t written any plugins yet and I’m also not really familiar on how to use OnDocFormSave. Are you generally suggesting to modify the articles call or are you suggesting to make a custom call and fetch the articles parameters?