Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Error using elements #9

Open
asecondwill opened this issue May 28, 2012 · 6 comments
Open

Error using elements #9

asecondwill opened this issue May 28, 2012 · 6 comments

Comments

@asecondwill
Copy link

Unexpected token "string" of value "datepicker"

This happens when doing:

{{ element 'datepicker' }}

if i change it to :

{% element 'datepicker' %}  

it calls the template. But how to pass options array?

if i do:

{% element 'datepicker' ,{
        'model' : 'AchievementPerson',
        'field' : 'occured',
        'label':'Date Completed' 
        }
%}

i get: Unexpected token "punctuation" of value ","

@asecondwill
Copy link
Author

also, the element isn't getting the view variables like a normal .ctp variable would. - variables set in the controller using $this->set('foo' , $foo);

@asecondwill
Copy link
Author

this is with cakePHP 2.1.2

@SamFleming
Copy link

I know this is mega old now but you could try:

{{ _view.element('element_file')

And, if you want to pass additional variables to it:

{{ _view.element('element_file', {'times': ['02:00', '04:00']}) }}

@AndreasPizsa
Copy link

passing parameters works using the with keyword

{% element 'element_file' with {'parameter':'value','parameter2':'value2'} %}

👍

Still need to figure out how to access the view variables from inside the element… :-/

@AndreasPizsa
Copy link

The workaround I use now to get around the view variables problem is that I pass them as parameters into the element, as described above.

There's actually an upside to this solution: it decouples the Element from the View itself, forcing a cleaner interface and thus Separation of Concerns. Code reuse FTW.

@predominant
Copy link
Owner

Just as elements were intended.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants