ProcessWire - Hanna Code (Module): Unterschied zwischen den Versionen
Aus Wikizone
| Zeile 54: | Zeile 54: | ||
echo $out; | echo $out; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | + | === Templates === | |
<?php | <?php | ||
echo(urls()->templates); | echo(urls()->templates); | ||
Version vom 30. September 2020, 10:06 Uhr
TextformatterHannaCode
Easily insert any complex HTML, Javascript or PHP output in your ProcessWire content by creating your own Hanna code tags.
https://github.com/ryancramerdesign/ProcessHannaCode#using-hanna-code-from-the-api
Hanna Code Snippets
Image from RepeaterMatrix or Repeater
<?php
// include a image from the parent page
if (!function_exists('getImagePage')) {
function getImagePage($myPage, $level=1){
// if in repeater or repeaterMatrix find the first parent ProcessWire\Page Page
$maxLevel=5;
if( get_class($myPage) == 'ProcessWire\RepeaterMatrixPage' || get_class($myPage) == 'ProcessWire\RepeaterPage') {
$level +=1;
if($level > $maxLevel) return false;
$forPage = $myPage->getForPage();
//var_dump( $myPage->getForPage());
//echo("<p>next Level: ".get_class($forPage)."</p>");
return $myPage = getImagePage($forPage);
}else if( get_class($myPage) == 'ProcessWire\Page'){
return $myPage;
}
}
}
$out = '';
$imagePage = getImagePage($page);
$images = $imagePage->images;
$imgTag = '';
if($images){
if(isset($file)){
isset($width) ? $image = $images->get($file)->width($width) : $image = $images->get($file);
$imgTag .= "<img src='$image->url'";
if(isset($width)) $imgTag .= " width='$width'";
if(isset($class)) $imgTag .= " class='$class'";
if(isset($style)) $imgTag .= " style='$style'";
$imgTag .= '>';
$out = $imgTag;
}else{
$out .= "<p>Gib einen Bildnamen an z.B.</p>";
foreach($images as $image){
$out .= '<p>[[image file="'.$image->name.'"]]</p>';
}
}
}else{
$out .= '<p>Keine Bilder auf der Seite gefunden</p>';
}
echo $out;
Templates
<?php echo(urls()->templates);