The difficulty is to build the HTML grid as I have to a balance of <li>sponsor</li> within the colomn.
Actually, the aossiciation has 31 sponsors but the amount of sponsors must be flexible. In a couple of mounth, we can have 20 sponsors or 45 sponsors. For example, if later we have 45 spensors, I would like to have the list of 15 sponsors in each column.
I can start filling the first column, but how can I know the balance? **With getResource, can we calculate the amount of published resources?**and then, calculating the 1/3, 2/3, 3/3. In that way, I could build the first column with the 1/3 of the sponsors, then the second column with the 2/3 and the third column with the rest?
How would you fill a such grid? (I have to respect the HTML coce)
If you use pdoResources (instead of getResources), you can set the &return property to data to get the raw data back. When you call pdoResources in a snippet, you can then format the returned data however you like. Something like this:
<?php
// Run pdoResources and return raw data
$results = $modx->runSnippet('pdoResources', [
'parents' => 11,
'limit' => 0,
'return' => 'data'
]);
$result_amount = count($results); // Determine the amount of results
$amount_per_column = ceil($result_amount / 3); // Calculate the amount of results in a column
$counter = 0;
$output = ''; // The output string
//$output .= '...'; // Add some HTML to the output to start the first column
foreach ($results as $result){
$output .= $modx->getChunk('some_chunk', $result);
$counter++;
if ($counter >= $amount_per_column){
$counter = 0;
//$output .= '...'; // Add some HTML to the output to finish the column and start a new one
}
}
//$output .= '...'; // Add some HTML to the output to complete the last column
return $output;
If I can have letter, that better, but the number is fine.
I tried to add idx and to get the incrementing number in my CHUNK with [[+idx]], but it does not work
<?php
// Run pdoResources and return raw data
$results = $modx->runSnippet('pdoResources', [
'parents' => 8,
'idx' => 1,
'sortby'=> '{"longtitle":"ASC", "pagetitle":"ASC"}',
'showUnpublished' => false,
'limit' => 0,
'return' => 'data'
]);
$result_amount = count($results); // Determine the amount of results
$amount_per_column = ceil($result_amount / 3); // Calculate the amount of results in a column
$counter = 0;
$output = ''; // The output string
$output .= '<div class="container well3">
<h3 class="wow fadeIn" data-wow-delay="0.2s">Nos sponsors</h3>
<div class="row">
<div class="grid_4 wow fadeIn" data-wow-delay="0.4s"><ul class="marked-list">
'; // Add some HTML to the output to start the first column
foreach ($results as $result){
$output .= $modx->getChunk('sponsorsTpl', $result);
$counter++;
if ($counter >= $amount_per_column){
$counter = 0;
$output .= '</ul></div>
<div class="grid_4 wow fadeIn" data-wow-delay="0.6s"><ul class="marked-list">'; // Add some HTML to the output to finish the column and start a new one
}
}
$output .= '</ul></div>
</div>
</div>'; // Add some HTML to the output to complete the last column
return $output;
I saw in the doc, there is that option but I should badly use it.
Second question.
Each of my sponsor, I create a resource and the type is link
In the link field, I saved a URL and I am tried to get it into the href=""
To retreive retreive the page or long title, I can use [[+pagetitle]], but it does not work with [[+link]] or [[+content]]. Is there a different way to call it?
In getResourcem there is a properties ‘includeContent’. With pdo resources, is there something similar that I need to activate? I will need to test the link field, because if no URL is saved, I will remove the a attribute
Great, thank a lot for your help, I make the following changes.
I used idx variable to return letter and I used $nb instead of $couter, because counter get back the value of 0 at each column.
Thanks!!
<?php
// Run pdoResources and return raw data
$alpha = array('A','B','C','D','E','F','G','H','I','J','K', 'L','M','N','O','P','Q','R','S','T','U','V','W','X ','Y','Z');
$results = $modx->runSnippet('pdoResources', [
'parents' => 8,
//'idx' => 1,
'includeContent' => '1',
'sortby'=> '{"longtitle":"ASC", "pagetitle":"ASC"}',
'showUnpublished' => false,
'limit' => 0,
'return' => 'data'
]);
$result_amount = count($results); // Determine the amount of results
$amount_per_column = ceil($result_amount / 3); // Calculate the amount of results in a column
$nb = 0;
$counter = 0;
$output = ''; // The output string
$output .= '<div class="container well3">
<h3 class="wow fadeIn" data-wow-delay="0.2s">Nos sponsors</h3>
<div class="row">
<div class="grid_4 wow fadeIn" data-wow-delay="0.4s"><ul class="marked-list">
'; // Add some HTML to the output to start the first column
foreach ($results as $result){
$result['idx'] = $alpha[$nb];
$output .= $modx->getChunk('sponsorsTpl', $result);
$nb++;
$counter++;
if ($counter >= $amount_per_column){
$counter = 0;
$output .= '</ul></div>
<div class="grid_4 wow fadeIn" data-wow-delay="0.6s"><ul class="marked-list">'; // Add some HTML to the output to finish the column and start a new one
}
}
$output .= '</ul></div>
</div>
</div>'; // Add some HTML to the output to complete the last column
return $output;