Skip to content

Instantly share code, notes, and snippets.

@Tramp1357
Last active November 17, 2015 09:50
Show Gist options
  • Save Tramp1357/cc2334428add09fc4d05 to your computer and use it in GitHub Desktop.
Save Tramp1357/cc2334428add09fc4d05 to your computer and use it in GitHub Desktop.
breadcrumbs на процессоре для MODX
<?php
class modSiteWebBreadcrumbsProcessor extends modProcessor{
public function initialize(){
$this->setDefaultProperties(array(
'startId' => 0,
'excludeDocs' => array(),
'showHidden' => true,
'showUnpub' => false,
'showDeleted' => false,
'showHome' => false,
));
return parent::initialize();
}
public function process() {
$bc_path = array();
$resource = $this->modx->resource;
$index=$this->modx->getOption('site_start',1);
//стоим в голове, нечего выводить
if($resource->get('id') != $this->getProperty('startId')){
//соберем цепочку родителей
$r=$resource->toArray();
unset($r['content']);
$bc_path[]=$r;
while($resource = $resource->getOne('Parent')) {
if (in_array($resource->id, $this->getProperty('excludeDocs'))
|| !$this->getProperty('showHidden') && $resource->hidemenu
|| !$this->getProperty('showUnpub') && !$resource->published
|| !$this->getProperty('showDeleted') && $resource->deleted
){
continue;
}
$r=$resource->toArray();
unset($r['content']);
array_unshift($bc_path,$r);
if($r['id']==$index) $index=0;
if($resource->id==$this->getProperty('startId')) break;
}
if($index && $this->getProperty('showHome')){
$r=$this->modx->getObject('modResource',$index)->toArray();
array_unshift($bc_path,$r);
}
}
return $this->success('', $bc_path);
}
}
return 'modSiteWebBreadcrumbsProcessor';
{$params=['startId'=>37]}
{processor action='site/web/breadcrumbs' ns=modxsite params=$params assign=result}
<div class="breadcrumbs">
{$total = count($result['object'])}
{$counter = 0}
{foreach $result.object as $object}
{$counter=$counter+1}
{if $counter<$total}
<span itemscope="itemscope" itemtype="http://data-vocabulary.org/Breadcrumb">
<a itemprop="url" rel="{$object.pagetitle}" href="{$object.uri}">
<span itemprop="title">{$object.pagetitle}</span></a></span>
/
{else}
<span itemscope="itemscope">{$object.pagetitle}</span>
{/if}
{/foreach}
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment