0

I want to use this in a phtml:

<?php 
$kataloge_dir = '../media/downloads/dlbereich/kataloge/';   
$kataloge = array_diff(scandir($kataloge_dir), array('..', '.'));

$kataloge_thumb_dir = '../media/downloads/dlbereich/kataloge-thumb/';   
$kataloge_thumb = array_diff(scandir($kataloge_thumb_dir), array('..', '.'));

$broschueren_dir = '../media/downloads/dlbereich/broschueren/'; 
$broschueren = array_diff(scandir($broschueren_dir), array('..', '.'));

$broschueren_thumb_dir = '../media/downloads/dlbereich/broschueren-thumb/'; 
$broschueren_thumb = array_diff(scandir($broschueren_thumb_dir), array('..', '.'));

$flyerlang_dir = '../media/downloads/dlbereich/flyerdinlang/';  
$flyerlang = array_diff(scandir($flyerlang_dir), array('..', '.'));

$flyerlang_thumb_dir = '../media/downloads/dlbereich/flyerdinlang-thumb/';  
$flyerlang_thumb = array_diff(scandir($flyerlang_thumb_dir), array('..', '.'));

$flyerdin4_dir = '../media/downloads/dlbereich/flyerdina4/';    
$flyerdin4 = array_diff(scandir($flyerdin4_dir), array('..', '.'));

$flyerdin4_thumb_dir = '../media/downloads/dlbereich/flyerdina4-thumb/';    
$flyerdin4_thumb = array_diff(scandir($flyerdin4_thumb_dir), array('..', '.'));

$preislisten_dir = '../media/downloads/dlbereich/preislisten/'; 
$preislisten = array_diff(scandir($preislisten_dir), array('..', '.'));

$preislisten_thumb_dir = '../media/downloads/dlbereich/preislisten-thumb/'; 
$preislisten_thumb = array_diff(scandir($preislisten_thumb_dir), array('..', '.'));

$technik_dir = '../media/downloads/dlbereich/technik/'; 
$technik = array_diff(scandir($technik_dir), array('..', '.'));

$technik_thumb_dir = '../media/downloads/dlbereich/technik-thumb/'; 
$technik_thumb = array_diff(scandir($technik_thumb_dir), array('..', '.'));

$poster_dir = '../media/downloads/dlbereich/poster/';   
$poster = array_diff(scandir($poster_dir), array('..', '.'));

$poster_thumb_dir = '../media/downloads/dlbereich/poster-thumb/';   
$poster_thumb = array_diff(scandir($poster_thumb_dir), array('..', '.'));
?>
<p><h2>Download Übersicht:</h2></p>
<button class="collapsible">Kataloge</button>
<div class="content">
<p>
<?php
foreach ($kataloge as $key => $kataloge_link)
{
    echo "<div class='boxt'>
    <div class='boxt-text'><a href='/media/downloads/dlbereich/kataloge/".$kataloge_link."'>".$kataloge_link."</a></div><div class='boxt-img'><a href='/media/downloads/dlbereich/kataloge/".$kataloge_link."'><img src='/media/downloads/dlbereich/kataloge-thumb/".$kataloge_thumb[$key]."' alt='".$kataloge_link."' /></a></div>
    </div><br>";
}
?>  
</p>
</div>
<button class="collapsible">Broschüren</button>
<div class="content">
  <p>
    <?php
foreach ($broschueren as $key1 => $broschueren_link)
{
    echo "<div class='boxt'>
    <div class='boxt-text2'><a href='/media/downloads/dlbereich/broschueren/".$broschueren_link."'>".$broschueren_link."</a></div><div class='boxt-img2'><a href='/media/downloads/dlbereich/broschueren/".$broschueren_link."'><img src='/media/downloads/dlbereich/broschueren-thumb/".$broschueren_thumb[$key1]."' alt='".$broschueren_link."' /></a></div>
    </div><br>";
}
?>  
    </p>
</div>
<button class="collapsible">Flyer (DIN lang)</button>
<div class="content">
 <p>
<?php
foreach ($flyerlang as $key3 => $flyerlang_link)
{
    echo "<div class='boxt'>
    <div class='boxt-text'><a href='/media/downloads/dlbereich/flyerdinlang/".$flyerlang_link."'>".$flyerlang_link."</a></div><div class='boxt-img'><a href='/media/downloads/dlbereich/flyerdinlang/".$flyerlang_link."'><img src='/media/downloads/dlbereich/flyerdinlang-thumb/".$flyerlang_thumb[$key3]."' alt='".$flyerlang_link."' /></a></div>
    </div><br>";
}
?>      
</p>
</div>
<button class="collapsible">Flyer (DIN A4)</button>
<div class="content">
 <p>
<?php
foreach ($flyerdin4 as $key4 => $flyerdin4_link)
{
    echo "<div class='boxt'>
    <div class='boxt-text'><a href='/media/downloads/dlbereich/flyerdina4".$flyerdin4_link."'>".$flyerdin4_link."</a></div><div class='boxt-img'><a href='/media/downloads/dlbereich/flyerdina4/".$flyerdin4_link."'><img src='/media/downloads/dlbereich/flyerdina4-thumb/".$flyerdin4_thumb[$key4]."' alt='".$flyerdin4_link."' /></a></div>
    </div><br>";
}
?>  
</p>
</div>
<button class="collapsible">Preislisten</button>
<div class="content">
 <p>
<?php
foreach ($preislisten as $key5 => $preislisten_link)
{
    echo "<div class='boxt'>
    <div class='boxt-text'><a href='/media/downloads/dlbereich/preislisten".$preislisten_link."'>".$preislisten_link."</a></div><div class='boxt-img'><a href='/media/downloads/dlbereich/preislisten/".$preislisten_link."'><img src='/media/downloads/dlbereich/preislisten-thumb/".$preislisten_thumb[$key5]."' alt='".$preislisten_link."' /></a></div>
    </div><br>";
}
?>      
</p>
</div>
<button class="collapsible">Technik</button>
<div class="content">
 <p>
<?php
foreach ($technik as $key6 => $technik_link)
{
    echo "<div class='boxt'>
    <div class='boxt-text'><a href='/media/downloads/dlbereich/technik".$technik_link."'>".$technik_link."</a></div><div class='boxt-img'><a href='/media/downloads/dlbereich/technik/".$technik_link."'><img src='/media/downloads/dlbereich/technik-thumb/".$technik_thumb[$key6]."' alt='".$technik_link."' /></a></div>
    </div><br>";
}
?>      
</p>
</div>
<button class="collapsible">Poster</button>
<div class="content">
 <p>
<?php
foreach ($poster as $key7 => $poster_link)
{
    echo "<div class='boxt'>
    <div class='boxt-text'><a href='/media/downloads/dlbereich/poster".$poster_link."'>".$poster_link."</a></div><div class='boxt-img'><a href='/media/downloads/dlbereich/poster/".$poster_link."'><img src='/media/downloads/dlbereich/poster-thumb/".$poster_thumb[$key7]."' alt='".$poster_link."' /></a></div>
    </div><br>";
}
?>      
</p>
</div>
<script>
var coll = document.getElementsByClassName("collapsible");
var i;

for (i = 0; i < coll.length; i++) {
  coll[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var content = this.nextElementSibling;
    if (content.style.display === "block") {
      content.style.display = "none";
    } else {
      content.style.display = "block";
    }
  });
}
</script>

Is there a way to use it in Magento 1.9? I get allways an Error.

  • 1
    What error did you get? Also where is this file being used? – AJ47 Apr 5 at 12:47
  • If i use vardump to get info i get value NULL. I think there is a problem with scandir in Magento. The file is not in use. – Marcel Apr 5 at 13:01
  • instead of using relative paths, have you tried using absolute path to the directories? – AJ47 Apr 5 at 13:09
  • Yes I tried with absolut path before. The path are OK. – Marcel Apr 8 at 6:56
0

This has nothing to loose in a .phtml you have to create a block class and put your PHP there.

Always keep the php in template files to a minimum.

https://devdocs.magento.com/guides/m1x/magefordev/mage-for-dev-4.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.