One-pager set up NOT as home page

Hello,

I try to realize this (http://getkirby.com/docs/solutions/one-pager#the-code-home-php-code-template) set up for a subpage – so not for the home page – but since everything turtles one level down I have difficulties to identify each instance where a subpage or a sub-subpage (as in the project folder) is addressed.

Background: I have a site with much information but I want a shorter version in English since not all content is going to be translated. This English content is meant to be displayed as a one-pager.

So instead of the home.php I have an english.php and instead of a code snippet such as

<?php foreach($pages->visible() as $section): ?>

I use

<?php foreach(page('english')->children()->visible() as $section): ?>

So far it does not work. I am not a real PHP professional, so I don’t know the extent of my ignorance here, but I have the impression that I do something wrong with the snippets. Is anybody around here who has done this before and could give me some basic information?

Thanks!

Could you post your structure and the names of the text files? Also, do you use any controllers? Then the corresponding controllers. The error might be there or with the naming of the snippets, or the passing of the correct variables.

Thanks for the reply @texnixe!

Oh, I don’t have any controllers.

The structure is something like this:

1-about
2-publications
3-projects
    /1-project-1
    /2-project-2
    /3-project-3
4-english
    /1-about-en
    /2-publications-en
    /3-projects-en
        /1-project-en-1
        /2-project-en-2
        /3-project-en-3

Each of the respective folder has a .txt-file: english.txt, about-en.txt, publications-en.txt, projects-en.txt, project-en-1.txt, project-en-2.txt, project-en-3.txt

This would be the english.php (instead of home.php), located in the templates folder:

<?php snippet('header') ?>

<section>
	<?php foreach(page('english')->children()->visible() as $section): ?>
	<?php snippet($section->uid()) ?>
	<!— html for each content section —>
	<?php endforeach ?>
</section>

<?php snippet('footer') ?>

These are the snippets in the snippets folder:

about-en.php

<section>
  <h1><?php echo $data->title()->html() ?></h1>
  <?php echo $data->text()->kirbytext() ?>
</section>

projects-en.php

<section>
  <h1><?php echo $data->title()->html() ?></h1>
  <?php echo $data->text()->kirbytext() ?>
  <ul>
    <?php foreach($data->children()->visible()->limit(6) as $project): ?>
      <li>
      	<h2><a href="<?php echo $project->url() ?>"><?php echo $project->title()->html() ?></a></h2>
      	<p><?php echo $project->text()->excerpt(80) ?> <a href="<?php echo $project->url() ?>">read&nbsp;more&nbsp;→</a></p>
        <figure>
          <img src="<?php echo $project->images()->first()->url() ?>" alt="<?php echo $project->title()->html() ?>">
        </figure>
      </li>
    <?php endforeach ?>
  </ul>
</section>

You are using a variable $data in your snippets without ever defining what $data is.

You need to pass the variable to the snippet like this:

<?php snippet('header') ?>

<section>
	<?php foreach(page('english')->children()->visible() as $section): ?>
	<?php snippet($section->uid(), array('data' => $section)) ?>
	<!— html for each content section —>
	<?php endforeach ?>
</section>

<?php snippet('footer') ?>

It helps if you turn on debugging in your config.php

c::set('debug', true);

Yes I forgot the array. But it does not change anything here. And also: each “project” in projects-en.php should be “project-en”, I guess.

Anyhow, it is very late! Thanks for taking your time. Tomorrow is going to be a new and inspiring day. So good night for now!

@texnix, sorry for not giving a feedback so far. In fact I don’t have any, since I didn’t get this to run, alas! Also I I wonder how to chose between different templates for each section on the panel, since the sections snippets are not shown in the template select field. (Or are they?)

I will try two different setups now though (as a workaround):

  1. to create a onepage template with fields for editable content (like about and contact) and combine it with snippets for the dynamic content. (Something like this: https://github.com/TimOetting/kirby-builder)
  2. to see whether I can achieve sortable sections by creating new article templates instead (without losing my way in a strange loop…).

I don’t understand why this does not work as expected, it does in my test install. Here is what I did:

  1. Created a page structure like yours above, with a page “english” with an english.txt in it and with its subfolders.
  2. Created a template english.php with the code from above:
<?php snippet('header') ?>

<section>
	<?php foreach(page('english')->children()->visible() as $section): ?>
	<?php snippet($section->uid(), array('data' => $section)) ?>
	<!— html for each content section —>
	<?php endforeach ?>
</section>

<?php snippet('footer') ?>
  1. Created the following snippets in /site/snippets: about-en.php, projects-en.php, and publications-en.php.

  2. If you want to edit these subpages in the panel, you have to create blueprints with the names of the text files in english/about-en, /english/projects-en, and /english/publications-en, if the text files are called about-en.txt, projects-en.txt, and publications-en.txt, the blueprint names must be about-en.php, projects-en.php, and publications-en.php.

And to answer your question above: No, the snippets are not shown in the select field of the panel, but as I wrote above, you can nevertheless have blueprints for your snippets.

Wonderful! I owe you something.