New answers tagged

1

I'm not sure what recentlyViewed() is and what it returns but to query today's entry, you can do: {# Today in atom format #} {% set timeAgo = date('today') | atom %} {% set recentMerchantsOffers = craft.entries() .section('offers') .postDate(">= #{timeAgo}") .all() %}


0

A blanket relatedTo query should do the trick. craft.entries().section('thename').relatedTo(currentUser).all()


1

The second parameter of the input function is the name attribute, which you currently have as contactName. Assigning it in the options like you have does not override the initial supplied parameter. Try this: {{ input('text', 'fields[contactName]', entry.contactName, { id: 'contactName' }) }}


2

You're getting the error because of Twig's operator precedence. Filters take priority over math. So basically Twig was trying change var2 to a percentage first instead of using the results of the math expression first, ie: {{ var1 / (var2 | percentage) }} Generally this behavior is usually what you want but sometimes there's edge cases where it doesn't work ...


3

To convert the results of an Element Query into a custom key/value array you can use the index filter to specify what you want to use as the keys. So for example if you want the category slugs to be the keys and the category titles to be the values you'd do it like this: {% set indexedCats = craft.categories.all()|index('slug') %} {{ macro.select('name', ...


1

{% if not currentUser %}{# or whatever #} {% exit 401 %}{# Or whatever HTTP status appropriate template it should be #} {% endif %} ... the rest of your template ...


1

If this related to an entire twig template, you could include it inside an if statement: {% if not devMode %}{% include '_includes/google-analytics.twig' -%}{% endif %} If you need to exit a twig template early (based on some value), Oli's answer is what you might want to look at.


1

Depending on what you exactly need to happen, the {% exit %} (docs) tag my be an option for you.


1

I got the Craft percentage filter to work by enclosing the calculation in parens, like this: {{ (var1 / var2) | percentage }}


1

I am not sure if the code does what you want it to do - but nevertheless you have three {% endif %} but only two {% if %}. Assuming the line dynamicEl: [{% endif %}{%- if not loop.last -%}{ "src": "{{ image.getUrl('wsHigh') }}", "width":"{{ img.getWidth('wsHigh') }}", "height":"{{ img.getHeight('wsHigh') ...


1

As you can see from the screenshot below and as Oli already mentioned, you can simply drag the content blocks on a page and hit the save button. That said, this is possible with contentblocks that are in a matrixfield. If you have regular fields for your page, you will need to arrange them in the section setup. Only matrix block elements can be arranged ...


3

I solved this by adding a module that is supposed to act as a sitemodule with different functions I use over most of my projects. Inside that module you register an asset bundle that ultimately adds a CSS stylesheet to the controlpanel. This way you can alter the look of the loginpage without tampering with any of Crafts innards. As can be seen from the ...


2

You can add a logo to the login page by uploading one to Settings → General Login Page Logo. If you need further tweaking, you could use the Control Panel CSS plugin. I wouldn't recommend modifying Craft's templates.


4

Immediately found a solution! {% set newsQuery = craft.entries({ section: 'news', after: now|date_modify('0:00 -1 months'), }) %}


Top 50 recent answers are included