*This post got really long, the actual problem are at the end of the post but here you can read how it all works.*
There is a few different chunk’s, snippet’s and one TV that is included so this can get quite a large post, it’s allso in swedish I’m afraid, here is the order and code:
1. A document that has a number of TV’s like product image, price and so on and some TV’s that decides which chunks to be included in the document (a way to only have one template per css design, I want the site to easily change appearance). I used the guide I found on
http://wiki.modxcms.com/index.php/Create_TV-Based_Chunks.
2. A TV that decides if the document content is a text site or a product, the value are set to "produktinnehall".
Variabelnamn (variable name): [*funktioner_sidinnehall_mitten*]
Inmatningstyp (input type): Radio Options
Inmatningsvärden (input value): @EVAL return $modx->runSnippet('getChunks',array('category'=>'funktioner_sidinnehall_mitten'));
Standardvärde (standard value): textinnehall
Widget: Delimited List
Delimiter: ,
3. The getChunks snippet code are:
<?php
$q_chunks = $modx->db->query('
SELECT
chunk.*
FROM '.$modx->getFullTableName('site_htmlsnippets').' AS chunk
INNER JOIN '.$modx->getFullTableName('categories').' AS category
ON chunk.category = category.id
WHERE
category.category IN ("'.$category.'")
ORDER BY
name
');
$ar_chunks = array();
while ($row = $modx->db->getRow($q_chunks)) {
$ar_chunks[] = $row['name'];
}
$l_chunks = implode("||",$ar_chunks);
return $l_chunks;
?>
4. The category "funktioner_sidinnehall_mitten" contains two chunks: produktinnehall (this is the value set) and textinnehall
5. A chunk that is inserted in the middle of the product document:
{{funktioner_sidinnehall_overst_vanster}}
<div id="sidinnehall">
{{funktioner_sidinnehall_over_hoger}}
{{funktioner_sidinnehall_mitten}} (this is the intresting chunk)
<div id="funktioner_botten">
{{funktioner_sidinnehall_under_vanster}}
{{funktioner_sidinnehall_under_hoger}}
<div class="rensa">
{{funktioner_sidinnehall_botten_vanster}}
</div>
</div>
</div>
Above this chunk is the html head and open body tag chunk and below the footer
6. The chunk "funktioner_sidinnehall_mitten" contains a snippet call to "chunkListParser" that basically includes the chunks that has the same names set by the TV "funktioner_sidinnehall_mitten" that in our case is set to "produktinnehall". In short, this call includes the chunk "produktinnehall" in the final document. All snippet calls from now on has to be called chached as I understand it since this call is uncached, if I try an uncached snippet from now on I only get the call printed in the final document (as usual).
[!chunkListParser? &chunks=`[*funktioner_sidinnehall_mitten*]` &wrapperdiv=`funktioner_sidinnehall_mitten`!]
7. The chunkListParser snippet code are:
<?php
$ar_chunks = split(',',$chunks);
$ar_chunks = array_unique($ar_chunks);
$output = '';
foreach ($ar_chunks as $chunk) {
if ($chunk != '') {
$c = $modx->getChunk($chunk);
if ($c) $output .= $c;
}
}
if ($output != '' && isset($wrapperdiv)) {
$output = '<div id="'.$wrapperdiv.'">'.$output.'</div>';
}
return $output;
?>
8. The chunk "produktinnehall" contains:
<div id="produktfalt">
<h1 class="centrera">[*pagetitle*]</h1>
<div class="centrera"><img src="[*produkt_bild*]" alt="[*pagetitle*] width="250px" /></div>
<div class="produkt_pris"><p>[*produkt_pris*]:-</p></div>
<div id="produkt_text">[*content*]</div>
</div>
<div id="sidfalt_ram">
<div id="sidfalt">
<p>[[Breadcrumbs? &showHomeCrumb=`0` &showCurrentCrumb=`0`]]</p>
{{produkter_lista}}
</div>
</div>
<div id="sidfalt_ram_hoger"></div>
<div class="rensa"></div>
This is basically two parts, one (first part where id=produktfalt) that shows the current product on the right side and one (id=sidfalt) that has the chunk call {{produkter_lista}} that lists the other products in the same folder/category (has the same parent).
9. The chunk "produkter_lista" contains:
[[Ditto? &sortBy=`createdon` &sortDir=`ASC` &language=`svenska-utf8` &parents=`35` &display=`all` &summarize=`5` &paginate=`1` &paginateAlwaysShowLinks=`1` &tpl=`mall_produkter_lista`]]
<p>Visar <strong>[+start+]</strong> - <strong>[+stop+]</strong> av <strong>[+total+]</strong> Produkter | Sida <strong>[+currentPage+]</strong> av <strong>[+totalPages+]</strong> </p> <p>[+previous+] [+pages+] [+next+]</p>
This is where my problem is, when I set the &parents=`` parameter to 35 as in the code, everthing is fine as long as I only want to have one product catergory, computer parts a document container with document id 35 but when I change &parents=`35` to &parents=`[*parent*]` the product list in the final document lists the documents in the root instead of the products in the current documents parent folder.
That’s all the code, to me it seem like the variable [*parent*] is set to 0, if I make the ditto call with parents parameter empty like &parents=`` I get the output "No documents found" instead of the root documents for the site so maybe I have thought the wrong way of this problem, maybe the ditto call gets the [*parent*] value from the wrong document, why else would it be set to `0` and not ``.
I still have to find how to get it set to 35 when viewing a document inside the computer parts folder and det to 10 when viewing a document inside the shoe folder...
I’ve attatched a screen dump of the document structure, it’s simple but might help visualizing.
*edit*
I tryed with filter parameter instead like:
[[Ditto? &sortBy=`createdon` &sortDir=`ASC` &language=`svenska-utf8` &parents=`3` &display=`all` &summarize=`5` &paginate=`1` &paginateAlwaysShowLinks=`1` &tpl=`mall_produkter_lista` &filter=`parent,[*parent*],1` &depth=`10`]]
But the result is "No documents found", when I write [*parent*] outside the ditto call I get the output 35 and if I set &parents=`35` it works but &parents=`[*parent*]` does not.... How do I make it to prioritize [*parent*] so that is filled in before the ditto call is executed?