Good day. Faced a problem in modx. Found a lot of documentation on the Evo, but somehow it didn’t work on the Revo. Either nothing is said at all, or it is mentioned casually and important details are missing. In this regard, there is such a question: Resource page

He created a resource called an article, applied a standard template and applied such code in the content to display the content itself (sorry for the tautology). In the place where the little articles should be displayed attached [[$ news]] chunk.

Chunk news

As a result, the link a [href = "[[~ [[* id]]]]]"] refers to the article page itself, i.e. to the main resource "Articles". (In principle, it is logical). Well, respectively, [[* pagetitle]] and [[* introtext]] also take the context from the main resource "Articles".

What should be displayed in the articles themselves are created attached documents to the article resource:

Attached articles

Initially, I tried to make the articles snippet:

enter image description here

But the trouble is that the modD function getDocumentChildren () does not work on Revo, I found an analogue, as they wrote on the Internet, getChildIds (). But she returns nothing. (More precisely, I tried to call the result of the f-ii and echo and foreach () loop, but he just brought me 3 numbers: 14, 15, 16; instead, as I thought, * id, * pagetitle, * introtext).

As a result, kind people, help to make a page with articles. How to better and more correctly implement this action? (I would like to with the code)

Resource articles:

<div class="container-fluid articles_page"> <div class="container"><center> <h1>НОВОСТИ САЙТА</h1> <div class="divider"> </div> </center> <div class="news-block masonry" data-columns=""> [[$news]] </div> </div> </div> 

Chunk:

 <div> <a href="[[~[[*id]]]]"> <div class="thumbnail"> <img src="http://placehold.it/1280x720" class = "img-responsive" alt=\"\"> <div class=\"caption\"> <h3>[[*pagetitle]]</h3> <span class="date">[[*publishedon:date='%d/%b/%y']]</span> <p>[[*introtext]]</p> </div> </div> </a> </div> 

Snippet articles:

 <?php $results = $modx->getChildIds( $id = 13, $active = 1, $deleted = 0, 'id, pagetitle, published, introtext, content, menuindex, createdby, createdon, deleted, menutitle', $where = '', $sort='createdon', $dir='DESC', $limit = '' ); foreach($results as $key => $value) { if ($value["menutitle"] != "") { $title = $value["menutitle"]; } else{ $title = $value["pagetitle"]; } $items .= " <div> <a href=".$value["createdon"]."> <div class=\"thumbnail\"> <img src=\"http://placehold.it/1280x720\" class = \"img-responsive\" alt=\"\"> <div class=\"caption\"> <h3>".$title."</h3> ".$value["introtext"] ." </div> </div> </a> </div> "; } $output = " <div id=\"pagination\"> <a href=\"#\">< Назад</a> <a href=\"#\">Вперед ></a> </div> "; return $items.$output; 

Ps How to display a picture - a thumbnail on the page of articles?

  • Put the plug-in getResources and no need for any snippet to fence, everything has already been done for you google.ru/… - Jbyh
  • And how to apply it, do not tell me? - Kamil NHOT

2 answers 2

  [[!getResources? &parents=`[[*id]]` &tvPrefix=`` &includeTVs=`1` &tpl=`catalogItemTpl` &depth=`1` &showHidden=`0` &sortbyTVType=`integer` &sortbyTV=`price-for-m2` &sortdirTV=`ASC` &limit=`16` &where=`{"isfolder:!=":1}` ]] 

This is an example of a request, not specifically in your case ... But in general you can google, there are a lot of examples on the net. I also gave you the documentation. And so that the fields in a chunk are displayed for a specific resource and not the parent should be called instead of [[* * pagetitle]] - [[+ pagetitle]] etc.

  • can you clarify, is this embedded in a separate snippet? How can I call it from a chunk? - Kamil NHOT
  • news is a chunk template for a single article? - Jbyh
  • I advise you to watch some training videos on modx, you probably don't understand the basics ... - Jbyh
  • news is the chunk by which each news item is displayed on the articles page - Kamil NHOT
  • instead of calling the [[$ news]] call, you need to call the getResources snippet, where tpl = news , and in the news chunk, change the field calls as [[+ + pagetitle]] etc. - Jbyh
  1. In the main resource "Articles" add the following code:

 <div class="container-fluid articles_page"> <div class="container"><center> <h1>НОВОСТИ САЙТА</h1> <div class="divider"> </div> </center> <div class="news-block masonry" data-columns=""> [[!getResources? &showHidden=`1` &tpl=`news` &limit=`10` &includeContent=`1` &includeTVs=`1` &processTVs=`1`]] </div> </div> </div> 

enter image description here

Expose the desired template, etc.

  1. Create a TV ("Additional fields" in the "Elements") enter image description here

Tick ​​the templates that can apply them. TV is needed (in this case) to embed an image in the preview on the site. Also in the input parameters set the type "Image" 1. And in the final paragraph you create a Chunk with a sample: enter image description here

 <div> <a href="[[~[[+id]]]]"> <div class="thumbnail"> <img src="[[+tv.news_img:phpthumbof='w=300&h=350&zc=1']]" class = "img-responsive" alt=""> <div class="caption"> <h3>[[+pagetitle]]</h3> <span class="date">[[publishedon:date='%d/%b/%y]]</span> <p>[[+introtext]]</p> </div> </div> </a> </div> 

and basically everything. But it was impossible to do this, because everywhere the infa is either incomplete, either incomprehensibly written, or written, but not so (that is, nothing worked for those samples)

Thanks for attention.