Hot answers tagged

14

is defined - The variable has been defined, and set to any value (or null). is not null - The variable has been defined, and is specifically not null. In PHP terms, it's like the difference between is_null() vs. checking whether the variable exists using get_defined_vars() (see this Stack Overflow thread for a little more clarity) Try this experiment... ...


6

The first statement checks for the existence of var, the second checks that it has a value other than null and will throw and error if var does not exist. If you're not sure whether a variable exists, you should check if it exists first then check for its value to be safe. You could combine both statements like so {% if var is defined and var is not null %}...


5

You could combine the first three: {% if entry is defined and entry and entry.isEditable %} If the first or second part of this logic fails, it will not check the third part so no error will be thrown. The second part is for the rare cases that a variable with the name entry exists but is null. If entry is defined, it's always an entry (or at least it ...


4

You don't want to expose a Record to the template level for many reasons, including inadvertently letting a template call record.save() causing unexpected updates to the database, but you also don't want to expose any unnecessary data to the template (like "password", in your example). A bit more info on that here. This is where Models come in. They don't ...


2

Your blogroll can be treated as a PHP function. In order to use functions you have to pass the required parameters. In your case your blogroll expects the parameter entry {{ blogroll.blogroll(entry) }} or {{ blogroll.blogroll(category) }} will work


1

I found the issue about this problem. I have in my code {% set selectedCategory = craft.app.request.getQueryParam('category') %} but I change getQueryParam with queryParams('category'); {% set selectedCategory = craft.app.request.queryParams('category') %} and the problem was solved


1

Shooting in the dark here, but looking off this ticket and the ECM parameter value syntax in the docs, could you do something like: {% paginate craft.entries({ section : 'dealDirectory', limit : pageSize, startDate : '<=' ~ now endDate: 'or', '>= ' ~ now, 'not null' }) as pageInfo, dealEntries %} The or is a total guess based on the ...


1

craft()->request->getParam() is only going to check for the value as part of the query string in the URI or in POST if it is a POST request, which is why it's returning null on the edit entry page in the control panel (it isn't in either). But since it looks like you're using a template hook in your plugin, you can get the entry id directly from the ...


Only top voted, non community-wiki answers of a minimum length are eligible