In a twig I have the below and it outputs the page title+link.
{% for p in page.find('/wallpapers').children if p != page %}
<a href="{{p.url}}/">{{ p.title}}</a>
{% endfor %}
I have another variable for the image artistimg I have added this to the twig like below but the variable name doesn’t get outputted. I also tried changing this to page.artistimg but no name is added. I also tried changing p.title to p.folder (another variable in those md files) and nothing gets returned. So am I correct to say that page.find doesn’t work with any other variable other then page title
{% for p in page.find('/wallpapers').children if p != page %}
{{p.artistimg}} <a href="{{p.url}}/">{{ p.title}}</a>
{% endfor %}
I also tried the below to try and dump the image out using the variable but again nothing.
{% for p in page.find('/wallpapers').children if p != page %}
{{ dump(pages.find('/images/landing-page-thumbnails/'~page.header.artisti mg).media.images) }} <a href="{{p.url}}/">{{ p.title}}</a>
{% endfor %}
If I understand correctly this artistimg variable is a header variable of your children pages? In that case, you’d use:
—twig
{{ p.header.artistimg }}
to get its value. What you're trying to do next seems like it should work to me, apart from the typo (you have a space in `artisti mg`) and the fact that it should be `p.header` instead of `page.header`, providing your folder structure looks like:
Ah I can see where I was going wrong. I have managed to out this variable onto the page so it can be seen but still cant seem to get the image to appear. I have slightly modified the code based on your table code.
{% for p in page.find('/wallpapers').children if p != page %}
{{ dump(pages.find('/images/landing-page-thumbnails/').media[p.header.artistimg~'.jpg']) }} {{p.header.artistimg}} <a href="{{p.url}}/">{{ p.title}}</a>
{% endfor %}
—twig
{% for p in page.find(’/wallpapers’).children if p != page %}
{{ dump(pages.find(’/images/landing-page- thumbnails’).media.images[p.header.artistimg~’.jpg’]) }} {{p.header.artistimg}} {{ p.title}}
{% endfor %}
Note I removed the slash after `landing-page-thumbnails` and added `.images` behind `.media`
An easy way to find out where you're going wrong is to make your dump less specific and drill in step by step :) i.e. I start with `dump(pages.find('/images/landing-page-thumbnails/'))` and you'll notice it does not find the page with that trailing slash.
Any idea on how to make the front end display better? I have added in a table
<table>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
</tr>
<tr>
<td>{% for p in page.find('/wallpapers').children if p != page %}
{{ pages.find('/images/landing-page-thumbnails').media.images[p.header.artistimg~'.jpg'] }} <a href="{{p.url}}/">{{ p.title}}</a>
{% endfor %}</td>
</tr>
</table>
So everything appears under “1” in one column. I cant figure out how to make the 2nd image/link appear in column 2, next in column 3, next in column 4 before it starts over again in column 1.
That worked a treat I only just found out about the page.find working for child folders. I had manually created about 600 pages with hard coded children folder links. Will need to go over those again to make them work in this new method and delete the hardcoded table/links and add in a variable for the image but at least if any more get added to that section they will auto appear as opposed to manually being done.
Least my new section with about the double number of pages is pretty much complete thanks to you in one day (other manual one took me like over 2 weeks @ several hours a day).
I was just looking at Batch until I refreshed forum and you had already answered
So something like the above. The table code work’s for wallpapers and works for the videos top level child’s. What I cant figure out now is how to make child1 table output its sub childs.
{% for p in page.find('/videos/'~page.header.folder~'-videos/').children if p != page %}
The child1 already contains a folder variable that matches its name inside videos only thing its missing is the -videos aspect. I’m thinking with the code the twig is’nt going into the child just yet in order to pickout that variable (??!!!)
So sites folder structure is like that. for 02.wallpapers and 03.videos (top level) the original code is working. Now I am trying the same auto folder outputting at the artist-name-1 level (sub folder of parent) but the code points to only the parent folder so I was trying to add a variable here so it finds the sub folder…
{% for p in page.find('/videos/'~page.header.folder~'-videos/').children if p != page %}
If you only want the children of the current page, so when you are in artist-name-1-videos and you want to get the following pages: [ artist-video-1, artist-video-2, artist-video-3 ], you don’t need to use page.find, you can simply do:
—twig
{% for p in page.children %}
to loop through the children of the current page. Is thatt what you are looking for?
Do you know if anything can be done with empty columns? So let’s say the section is videos… for the particular artist I only have one video. The table outputs one row/column and the other 3 columns are blank and it looks a bit daft. Anyway to fill those columns (with something hard coded or just blank empty columns).
So that’s the result just wondering if anything can be done with that? Would not mind having hardcoded td’s to appear only if table needs it (so would have 3 max) and 1st instance all 3 would appear in 2nd one only 2 would appear and 3rd only 1 and 4th none as table is complete.
The batch filter in twig allows you to pass a second parameter that specifies how to fill ‘empty’ columns. http://twig.sensiolabs.org/doc/filters/batch.html
Might be a better alternative than the for loop with is divisible by I mentioned earlier.