Отдельное изображение для каждого раздела структуры

#
Отдельное изображение для каждого раздела структуры
Предлагаем вот такое решение на основе хлебных крошек:


  1. Создаем доп свойство xml_name = 'bilbord'
  2. В нужном месте шаблона пишем код


    <?php
    $structure = new Structure();
    $structure->ShowStructure(false, 'Билборд', array(), array());
    ?>


  3. Создаем xsl шаблон 'Билборд'


    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE xsl:stylesheet>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output xmlns="http://www.w3.org/TR/xhtml1/strict" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" encoding="utf-8" indent="yes" method="html" omit-xml-declaration="no" version="1.0" media-type="text/xml"/>
       
       <xsl:template match="/document">      

          <!-- Запишем в константу ID структуры, данные для которой будут выводиться пользователю -->
          <xsl:variable name="current_structure_id">
             <xsl:value-of select="structure/current_structure_id"/>
          </xsl:variable>

          <xsl:choose>

                <xsl:when test="count(//structure[@id = $current_structure_id]) &gt; 0 and //structure[@id = $current_structure_id]/propertys/property[@xml_name='bilbord']/value!=''">
             <xsl:apply-templates select="//structure[@id = $current_structure_id]">
                <xsl:with-param name="is_last_item" select="1"/>
             </xsl:apply-templates>
                        </xsl:when>

                <xsl:otherwise>
                            <img src="/templates/template7/images/2p/company.png" width="960" height="200" />
                        </xsl:otherwise>

          </xsl:choose>

       </xsl:template>
       
       <xsl:template match="structure">

          <xsl:param name="is_last_item" select="0"/>      

          <!-- Выбираем все узлы структуры всех уровней вложенности -->
          <xsl:apply-templates select="parent::structure"/>   

          <xsl:if test="$is_last_item != 0">
                          <img src="{propertys/property[@xml_name='bilbord']/file_path}" alt="" />
          </xsl:if>
       </xsl:template>
    </xsl:stylesheet>


#
Re: Отдельное изображение для каждого раздела структуры
Вот решение на PHP, оно лучше

<?php
$structure = new Structure();
// Получаем данные о текущей странице
$structure_parent_id = CURRENT_STRUCTURE_ID;
$structure_propertys_id = 14; // ID свойства с картинкой
$queue = array();
while ($structure_parent_id != 0)  {
   $row_structure = $structure->GetStructureItem($structure_parent_id);
   $row = $structure->GetStructurePropertyValue($structure_parent_id, $structure_propertys_id);
   $structure_parent_id =  $row_structure['structure_parent_id'];
   if($row['structure_propertys_values_file'] != NULL) {
       $queue[] = $row;
   }
}
if(count($queue) > 0) {
    $queue = array_reverse($queue);
    $last = array_pop($queue);
    $filename = $last['structure_propertys_values_file'];
    $dir = $structure->GetStructureItemDir($last['structure_id']);
    $bilbordpath = '/'.$dir.$filename;
} else {
    $bilbordpath = false;
}
if($bilbordpath != false) {
    echo '<img src="'.$bilbordpath.'" alt="" width="960" height="200">';
} else {
    echo 'default';
}
?>
#
Re: Отдельное изображение для каждого раздела структуры
а примерчик... (типа демки)?
#
Re: Отдельное изображение для каждого раздела структуры
Сайт, для которого разрабатывалось это решение, пока закрыт для публичного просмотра. Как только откроем - сразу покажем.
Авторизация