ProcessWire - Hanna Code (Module): Unterschied zwischen den Versionen
Aus Wikizone
| Zeile 57: | Zeile 57: | ||
<?php | <?php | ||
echo(urls()->templates); | echo(urls()->templates); | ||
| + | |||
| + | === Video === | ||
| + | <syntaxhighlight lang="php"> | ||
| + | <?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; | ||
| + | |||
| + | /* | ||
| + | <video style="width: 100%; height: auto;" preload="preload" playsinline="" controls="" uk-video="autoplay: true" aria-hidden="false"> | ||
| + | <source src="/site/assets/files/1680/kas-anmelden.mp4" type="video/mp4"> | ||
| + | Ihr Browser unterstützt kein Video Tag | ||
| + | </video> | ||
| + | */ | ||
| + | </syntaxhighlight> | ||
Version vom 4. Dezember 2020, 09:58 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
<?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;
/*
<video style="width: 100%; height: auto;" preload="preload" playsinline="" controls="" uk-video="autoplay: true" aria-hidden="false">
<source src="/site/assets/files/1680/kas-anmelden.mp4" type="video/mp4">
Ihr Browser unterstützt kein Video Tag
</video>
*/