ProcessWire - Hanna Code (Module): Unterschied zwischen den Versionen
Aus Wikizone
Steff (Diskussion | Beiträge) |
|||
| Zeile 163: | Zeile 163: | ||
$out .= '</ul>'; | $out .= '</ul>'; | ||
echo $out; | echo $out; | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | === Social Media Icons über Repeater === | ||
| + | <syntaxhighlight lang="php"> | ||
| + | <?php namespace ProcessWire; | ||
| + | |||
| + | // SOCIALMEDIA | ||
| + | $socialmedia = ''; | ||
| + | $p = $pages->get('/site-configuration/'); | ||
| + | //bd($p->r_socialicons); | ||
| + | foreach($p->r_socialicons as $item){ | ||
| + | if($item->link){ | ||
| + | $socialmedia .= '<li><a href="'.$item->link.'" target="_blank" description="'.$item->text.'"><img src="'.$item->single_image->width(48)->url.'" uk-tooltip="'.$item->text.'" alt="'.$item->text.'" title="'.$item->text.'"></a></li>'; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | return '<ul class="nav socialicons uk-flex uk-flex-center@m nmb">'.$socialmedia.'</ul>'; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Version vom 16. September 2022, 07:35 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);
Video
Von chargercube - todo security / video field statt dateifeld
<?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);
//var_dump($imagePage->name);
$files = $imagePage->files;
$videoTag = '';
$videoValid = false;
$styles = '';
if($files){
if(isset($file)){
$file = $files->get($file); // we need the file object not the file name
if(isset($width)) $styles = 'width: '.$width.'; max-width: 100%; height: auto;';
else $styles = 'width: 100%; height: auto;';
if($file){
$videoValid = true;
$videoTag .= '
<video style="'.$styles.'" preload="preload" playsinline="" controls="" uk-video="autoplay: false" aria-hidden="false">
<source src="'.$file->url.'" type="video/mp4">
Ihr Browser unterstützt kein Video Tag
</video>
';
$out = $videoTag;
}
}
if(!$videoValid){
$out .= "<p>Gib einen Dateinamen an. Dateien auf dieser Seite:.</p>";
foreach($files as $file){
$out .= '<p>[[video file="'.$file->name.'"]]</p>';
}
}
}else{
$out .= '<p>Keine Dateie auf der Seite gefunden</p>';
}
echo $out;
Heading
Genbänkle
Attributes
tag=h2 heading
<?php echo($heading); ?>
Next Events
Genbänkle
<?php
$today = strtotime(date('Y-m-d'));
$eventPage = $pages->get('/termine/');
$mySelector = "template=event,limit=2,sort=event_date,event_date>=$today";
$events = $pages->find($mySelector);
$eventListMarkup = '';
foreach($events as $event){
$eventListMarkup .= '<div class="date uk-text-muted">'.$event->event_date.'</div>';
$eventListMarkup .= '<p><a href="'.$event->url().'">'.$event->title.'</a></p>';
}
echo $eventListMarkup;
<?php namespace ProcessWire;
$out = '';
($attr['parent']) ? $parent = $pages->get($attr['parent']) : $parent = $page;
$children = $parent->children();
$out .= '<ul class="childnav">';
foreach ($children as $child){
$out .= '<li class="nav-item"><a class="nav-link" href="'.$child->url.'">'. $child->title . '</a></li>';
}
$out .= '</ul>';
echo $out;
Social Media Icons über Repeater
<?php namespace ProcessWire;
// SOCIALMEDIA
$socialmedia = '';
$p = $pages->get('/site-configuration/');
//bd($p->r_socialicons);
foreach($p->r_socialicons as $item){
if($item->link){
$socialmedia .= '<li><a href="'.$item->link.'" target="_blank" description="'.$item->text.'"><img src="'.$item->single_image->width(48)->url.'" uk-tooltip="'.$item->text.'" alt="'.$item->text.'" title="'.$item->text.'"></a></li>';
}
}
return '<ul class="nav socialicons uk-flex uk-flex-center@m nmb">'.$socialmedia.'</ul>';