Getting images and formated text from YAML field

Hi, I’m trying to store and retrieve information that includes an image and a detailed description. The description should be able to include links and paragraph breaks. However, my images don’t show and any links within the extended description break the array.

The images are saved in the same directory as the text file.

Here’s what my text file looks like:

----
Samples:
Sample1:
    Imagefile: sample-1.png
    Itemname: Item One
    URL: http://www.items.com/item_one
    Description: A long paragraph description featuring an (link: http://www.items.com/item_one popup: yes text: outbound link) with some more detailed text.

Sample2:
    Imagefile: sample-2.png
    Itemname: Item Two
    URL: http://www.items.com/item_two
    Description: A long paragraph description not featuring an outbound link with some more detailed text.

Sample3:
    Imagefile: sample-3.png
    Itemname: Item Three
    URL: http://www.items.com/item_three
    Description: A long paragraph description not featuring an outbound link with some more detailed text.
----

And this is how I ^imagine^ the php should be structured to get this to work…

<?php $samples = yaml($page->Samples()) ?>
<?php foreach($samples as $sample): ?>
<a href="<?php echo $sample['URL'] ?>" target="_blank"><img src="<?php echo $sample["Imagefile"] ?>" alt="<?php echo $sample["Itemname"] ?>"  /></a>
<p><?php echo $sample['Description'] ?></p>
<?php endforeach ?>

The HTML output ^looks^ okay, sort of:

<a target="_blank" href="http://www.items.com/item_one">
<img src="sample-1.png"></img></a>
<p>Array</p>
<a target="_blank" href="http://www.items.com/item_two">
<img src="sample-2.png"></img></a>
    <p>A long paragraph description not featuring an… </p>
<a target="_blank" href="http://www.items.com/item_three">
<img src="sample-3.png"></img></a>
<p>A long paragraph description not featuring an… </p>

The problem is, the images don’t show and if there is any formating in the long text, all it returns is ‘array’.

On the image issue, I think instead of

<?php echo $sample["Imagefile"] ?>

it should be something like

<?php echo $page->image($sample["Imagefile"])->url() ?>

Aha! yes that worked, thank you :smile:

Regarding the longer description, is there a way to specify that as text or multiline or something?

I think, you might have to save it as

Description: > 
    A long paragraph description not featuring an outbound link with some more detailed text.

And then use kirbytext()on it for the formatting, links etc.

<?php echo kirbytext($sample['Description']) ?>
1 Like

Why is the > and a new line necessary?

It’s the sort of thing that will throw my content editors.

It seems to be the YAML standard: http://learnxinyminutes.com/docs/yaml/

If that thing will throw off your content editors, why aren’t you using the panel for them?

Unfortunately adding kirbytext hasn’t worked.

The description shows up when I use <?php echo $star['Description'] ?>, but not at all with <?php echo kirbytext($sample['Description']) ?>

We’re planning on using Git to manage content, and the Panel isn’t particularly friendly for version control purposes. But that extra > probably won’t upset anyone too much :smile:

I don’t see any reason why the panel should get in the way of using version control?

I’m very open to being corrected! I’ve found in the past (using subversion and not Git admittedly) that files manged using the Panel caused havoc, if that’s not too strong a word, in the version control. There’s no possibility to commit or track who made the changes or anything, is there?

If you’re are planning to work locally on Git repos anyway, I think you could use the panel only locally to facilitate content editing, while a the local changes to content get pushed to a remote from where they are then deployed. Plus the content could live in a separate repo from the rest. There’s some discussion here about the best way to deploy using Git as well How to best organize files/folders/repos & the deploy strategy