Conditional text

Hi, I would like to use Kirby for a software documentation. It looks great so far but I’m not entirely sure how to tackle my problem.

I want to document two apps which are very similar on multiple platforms. I would like to be able to write a page where 90% of the information is the same on all platforms.

I started out with tags:

<?php

kirbytext::$tags['windows'] = array(
  'html' => function($tag) {
    return $tag->attr('windows');
  }
);

Now I can do this:

Unspecific text
(windows: 
## Windows-specific text
(image: windows-screenshot.png
)
Unspecific text

Is this a good way to go about this?

I would create a template that contains the unspecific text, then you can have two pages with their own content to populate the rest of that template.

I think it makes sense to use a Kirbytag for that, as that’s very flexible to use inside the content.

You can use a “wrapped tag” like the columns tag to wrap any text/code in a set of one opening and one closing windows tag (you could even generalize it so it would be os-specific: windows or os-specific: osx).
The callback inside would then check whether the condition is currently met (by using a URL param etc.) and then either render the Kirbytext between the tags or replace it with an empty string to remove the conditional information.

I think the solution depends on how you want to structure your content. If all text goes into one textarea field, then you could use kirbytags for the specific text elements.

BTW. Your approach above will not work as you can’t have Kirbytext tags within Kirbytext tags. You would have to go for one of the solutions described in this post No markdown parsing with kirbytags for this kind of more complicated tags.

Quick side note: That only applies to “normal” tags. If you use a pre filter like the columns tag does, you can actually use Kirbytags inside your tag.

@lukasbestle That’s exactly what I said as I was referring to the example given by @Amenti.

Thanks a lot. I went with a plugin (some changes to the columns-plugin) and added a switcher to my header which sets a cookie regarding the selected operating system.

Thanks for the hints. :smile:

If you want to have an alternative way, look at Why are you making this so complicated?

I know, this is for many web designers not their way, but it is my way.

Hint: look at Relational database

For your problem: the place to store the “software documentation” pages must not be the path to store the corresponding data.
And for me the corresponding data should be data and should not be saved outside from that data, that I or the admins could change within of the Panel.

You can add a link at the blueprints of your “software documentation” pages to the path of the corresponding data!

Good luck!