Svnt
April 26, 2017, 11:58am
1
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?
Svnt
April 26, 2017, 12:16pm
3
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”.
Then you are not passing the full path to the page to the page helper…
<?= page("blog/werbung/webinar")->text()->kirbytext() ?>
Svnt
April 26, 2017, 12:35pm
5
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.
Svnt
April 26, 2017, 1:02pm
8
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…
Svnt
April 26, 2017, 1:41pm
10
yes, solved, sorry for the disturbance