Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a little String variable in an Array Causes Syntax Error?

I'm trying to add a dash - and a defined string $pageurle right after the {target} sothat the url in the href (se below code) is extended with, naturally a dash and the contents of the variable $pageurle

See the existing piece of code into which I would like to inject the dash & variable right after the href:

// html for breadcrumbs
var $breadcrumb_templates = array(
    'separator' => '→',
    'link'      => '<a href="{target}">{name}</a>',
    'wrapper'   => '<div class="breadcrumbs">{items}</div>', 
);

Now, when I add the dash and the $pageurle, dreamweaver says i'm doing something wrong and shows an eror. I must be doing something stupid here... but what? Your ideas/code/improvements/possible dives into this matter are much appreciated by me.

enter image description here

like image 975
Sam Avatar asked Dec 07 '25 09:12

Sam


1 Answers

Pretty sure it's because class property initialising statements (the var gave it away), may only contain constants or literals.

You can't perform anything procedural in the statement.

Best to do this sort of thing in your constructor.

Edit

To illustrate

class MyClass
{
    public $breadcrumb_templates = array(
        'separator' => '&rarr;',
        'link'      => '<a href="{target}">{name}</a>',
        'wrapper'   => '<div class="breadcrumbs">{items}</div>',         
    );

    public function __construct($pageurle = null)
    {
        if (null !== $pageurle) {
            $this->breadcrumb_templates['link'] =
                sprintf('<a href="{target}-%s">{name}</a>', $pageurle);
        }
    }
}
like image 118
Phil Avatar answered Dec 09 '25 23:12

Phil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!