-
Notifications
You must be signed in to change notification settings - Fork 1
Using PHP in breadcrumb titles and paths
NOTE: This is planned for removal. See https://github.com/backdrop-contrib/custom_breadcrumbs/issues/6
If this advanced option is enabled at admin/settings/custom-breadcrumbs, then users given 'use php in custom breadcrumbs' permission can include small php code snippets (less than 250 characters)in the titles and/or paths fields of the add breadcrumb form. Be careful when enabling this option, as the incorrect use of php can break your site.
There are a couple of ways to use php in breadcrumbs and titles. One way is to return an array of breadcrumb titles in the titles text field and a corresponding array of breadcrumb paths in the paths text field such as
Titles:
<?php return array('title-1', 'title-2', 'title-3');?>
Paths:
<?php return array('path/to/title-1', 'path/to/title-2', 'path/to/title-3');?>
Sometimes, it may be more convenient to assign the titles and paths in the same code snippet, so you can also return an associate array with elements 'titles' and 'paths' that contain the titles and paths arrays, respectively. For example,
Titles:
<?php $titles = array('title-1', 'title-2', 'title-3');
$paths = array('path/to/title-1', 'path/to/title-2', 'path/to/title-3');
return array('titles' => $titles, 'paths' => $paths); ?>
(In this case, the paths text field will be ignored, so you can leave it empty).
When defined, appropriate objects such as $node, $term, or $view, will be available for these code snippets. Note that if this option is enabled and an array is not returned, then the module defaults to the standard operation of using each line of the titles and paths text fields to define a part of the breadcrumb.
For longer code snippets (greater than 250 characters), you can save your code snippet in an include file and use a php require_once statement in the titles and/or paths section of your custom breadcrumb to include and evaluate your code. See http://drupal.org/node/654766 for an example of this.