Problem loading content (images) from other page

Hello,

i need to include “advertisment-blocks” from another kirby content folder in blog posts.
I’ve tried to load the page and rendered it… so text works good but the URL to the images
are wrong.

    <?php if($page->advertisment() != ""): ?>
      <?= page("werbung/".$page->advertisment())->text()->kirbytext() ?> 
    <?php endif ?>

Any idea how to get the kirbytext rendered correct?

S.

1 Like

Do you mean the urls of images inside the kirbytext blocks? Are they ok if you reference such a page directly for testing?

Reference directly? Like:

<?= page("werbung/webinar")->text()->kirbytext() ?>

gives:

<img src="http://localhost/blog/webinar.png" alt="Cover Webinar">

But should be “blog/werbung/webinar.png”. :frowning:

Then you are not passing the full path to the page to the page helper…

<?= page("blog/werbung/webinar")->text()->kirbytext() ?>

Nope. Blog is my “root” folder. if i put it into the path i get a “Call to a member function text() on a non-object”.
Also the text of the “werbung/webinar” is correct after rendering… except the image URLs.

Is there another way to load and render kirbytext from another page?

What do you mean by root folder? Blog is your content folder?

If I do this in a fresh starterkit, content from another page is rendered correctly including image links, for example if I put this into the home.php

<?= page("blog/extending-kirby")->text()->kirbytext() ?>

all works nicely.

What is stored in your text file? The UID or the URI?

You could also try to use the toPage() method, but that would require the URI.

Ok, the problem is caused by a center plugin i use. If i center a image… the URL goes wrong.

<?php
/* Center Plugin
 *
 * @author Jimmy Rittenborg <jimmy@sitemarina.com>
 * @version 1.0.0
 */
kirbytext::$pre[] = function($kirbytext, $text) {
  $text = preg_replace_callback('!\(center(…|\.{3})\)(.*?)\((…|\.{3})center\)!is', function($matches) use($kirbytext) {
    $html = kirbytext($matches[2]);
    return '<div class="' . c::get('center.class', 'text-center') . '">' . $html . '</div>';
  }, $text);
  return $text;
};

now i have to figure out why this happens.

PS:

$html = $matches[2]; instead of kirbytexting the stuff in the plugin seems to work.

S.

1 Like

Oh, yes, I thought it might have been caused by a filter…

yes, solved, sorry for the disturbance :wink: