Nested folder with project thumbnails and short summary

Hi there,
I’m working on the redesign of a large photography magazine.
According to my preview questions I create a template that follow this structure:

001_issue
	- 001_hans_christian
	- 002_michael_lundgren
	- 003_marianne_bjornmyr
		[...]
	- 070_ji_zhou
	- cover_25_altered_landscapes.jpg
	- issue.en.txt
	- issue.it.txt

where:

  • the numbered folders are photography projects
  • the png is the cover of the current issue
  • issue.lang.txt the file with the content (issue + editorial)

You can see here the final template and the final code.

Now I want to keep the editorial on another page, and I’d like to use the following structure.

001_issue
	- projects
		- 001_hans_christian
		- 002_michael_lundgren
		- 003_marianne_bjornmyr
			[...]
		- 070_ji_zhou
	- editorial
		- editorial_cover.png
		- editorial.en.txt
		- editorial.it.txt
	- cover_25_altered_landscapes.jpg
	- issue.en.txt
	- issue.it.txt

where:

  • the projects folder contains the numbered folders with photography projects
  • the editorial folder keeps the editorial content and another image

So, the final question are:

  • how I can change the current template, in order to reach the nested folders — and display the projects thumbnails — and editorial?
  • how I can add a short summary in order to display 2 lines of the editorial and then a link to a full page with the editorial?

Thanks!

Fetch the projects (as seen from the issues page):

$projects = $page->children()->find('projects')->children();
$allProjectImages = $projects->images();
$editorial = $page->children()->find('editorial');

What do you mean by two lines of the editorial? Two sentences? Two paragraphs?

Hi @texnixe,
it works for the projects but not for the editorial. I did:

  <div class="text">
    <?php echo $page->children()->find('editorial')->kirbytext() ?>
  </div> 

About the editorial, I’d like to show an excerpt/summary in the issue page and a link to the full editorial page.

Something like:

<h2>Editorial</h2>
<p>Editorial excerpt lorem ipsum... <a href="#">read more</a> <p>

An example:

Title: To visit strange lands

----

Editorial:

Landscape is just a *metaphor* for a place of mind in the act of recognizing the beautiful and the sublime and in recording signs and the real presence of human beings, understanding even the proof of what is horrible, artifact and catastrophic.
Searching for new relationships between artificial and natural, a new balance takes shape, in which you can find vernacular elements, a different redefinition of clichés and the illusion of being able to manipulate nature through architecture. A multiplicity of looks and fragmented visions, deceiving, and further undermined by everything that occurs just after the recording act.

here the editorial.yml

title: Editorial
pages:
  template: editorial
files: false
fields:
  title:
    label: Title
    type:  text
  editorial:
    label: Editorial
    type:  textarea

Thanks!

Naa, not like that. Like this:

<?php 
$editorial = $page->children()->find('editorial');
?>
<h2><?= $editorial->title() ?></h2>
<div class="text">
    <?= $editorial->text()->excerpt(100) ?>
  </div>

Thanks! :slight_smile:

I’ve just added the link, like this:

<a href="<?php echo $editorial->url() ?>">read more</a>

So now, I need only to style the page and publish :wink:

@texnive, one more thing.

I’m trying to display a specific image for english editorial and italian editorial. So in my folder I have:

and in my code:

<?php 
$cover = $page->image()->find('editorial');
?>
<figure>
  <img src="<?php echo thumb($cover, array('width' => 880, 'height' => 900, 'upscale' => true))->url();?>" alt="<?php echo $page->title()->html() ?>">
</figure>

For sure I’m not a good developer :disappointed:

Don’t give up :slight_smile:

<?php 
$cover = $page->children()->find('editorial')->image('editorial' . $site->language()->code() . 'png');
?>

or, if the page is already defined:

<?php 
$cover = $editorial->image('editorial' . $site->language()->code() . 'png');
?>

Hi @texnixe,
I wrote this:

<?php snippet('header') ?>

<main class="main" role="main">

  <h1><time><?php echo $page->parent()->year() ?></time>/<?php echo $page->parent()->number() ?> &nbsp;<?php echo $page->parent->title()->html() ?></h1>

  <h2><?php echo $page->Title()->kirbytext() ?></h2>

  <?php 
  $cover = $page->children()->find('editorial')->image('editorial' . $site->language()->code() . 'png');
  ?>
  <figure>
    <img src="<?php echo thumb($cover, array('width' => 880, 'height' => 900, 'upscale' => true))->url();?>" alt="<?php echo $page->title()->html() ?>">
  </figure>

  <div class="text">
    <?php echo $page->text()->kirbytext() ?>
  </div> 
</main>

<?php snippet('footer') ?>

But doesn’t work, and I get this:

Whoops\Exception\ErrorException thrown with message "Call to a member function image() on null"

Stacktrace:
#0 Whoops\Exception\ErrorException in /Users/fabio/Sites/landscapestories/site/templates/editorial.php:12

Ok, I thought you were on the issue page/template. If that’s the editorial template, then it should just be:

 <?php 
  $cover = $page>image('editorial' . $site->language()->code() . 'png');
?>

I think there is an error in the syntax, because if I wrote:

 <?php 
  $cover = $page->image();
  ?>

  <figure>
    <img src="<?php echo thumb($cover, array('width' => 880, 'height' => 900, 'upscale' => true))->url();?>" alt="<?php echo $page->title()->html() ?>">
  </figure>

it shows the first image in the folder. If I wrote this:

  <?php 
  $cover = $page->image('editorial' . $site->language()->code() . 'png');
  ?>

  <figure>
    <img src="<?php echo thumb($cover, array('width' => 880, 'height' => 900, 'upscale' => true))->url();?>" alt="<?php echo $page->title()->html() ?>">
  </figure>

I get an error:

Error thrown with message “The given image is invalid”

Stacktrace:
#9 Error in /Users/fabio/Sites/landscapestories/kirby/vendor/getkirby/toolkit/lib/thumb.php:68
#8 Thumb:__construct in /Users/fabio/Sites/landscapestories/kirby/helpers.php:324
#7 thumb in /Users/fabio/Sites/landscapestories/site/templates/editorial.php:15
#6 require in /Users/fabio/Sites/landscapestories/kirby/vendor/getkirby/toolkit/lib/tpl.php:22
#5 Tpl:load in /Users/fabio/Sites/landscapestories/kirby/kirby/component/template.php:103
#4 Kirby\Component\Template:render in /Users/fabio/Sites/landscapestories/kirby/kirby.php:635
#3 Kirby:template in /Users/fabio/Sites/landscapestories/kirby/kirby.php:623
#2 Kirby:render in /Users/fabio/Sites/landscapestories/kirby/kirby/component/response.php:29
#1 Kirby\Component\Response:make in /Users/fabio/Sites/landscapestories/kirby/kirby.php:705
#0 Kirby:launch in /Users/fabio/Sites/landscapestories/index.php:16

Here a screenshot:

Ah, I forgot some dots, I’m afraid, forgive me :pray::

<?php
  $cover = $page->image('editorial' . '.' . $site->language()->code() . '.png');
if($cover): ?>
 <figure>
    <img src="<?php echo thumb($cover, array('width' => 880, 'height' => 900, 'upscale' => true))->url();?>" alt="<?php echo $page->title()->html() ?>">
  </figure>
<?pho endif ?>
1 Like

Thanks! :blush:
Much appreciated!