4

Since this is the top hit in Google, I'll guess it's handy to mention that craft.app.response.statusCode will display the statuscode in Craft v3 and up.


4

The asset volume needs to have public urls enabled. Thanks seb.


4

Environment variables don't exist in Craft 3 in the same way that they existed in Craft 2. Instead, they have been replaced with system environment variables and aliases. The Changes in Craft 3 docs explain what changes have been made and the Environmental Configuration explains how you can set these up and use them.


3

Have you considered using the Matrix field type? You could create a block for rich text, then a block for a contact form (or whatever widget). You could probably achieve what you're asking with a plugin but in my experience doing things like this in Redacter are prone to weirdness/bugginess (especially when in the hands of a client).


3

I'd rather: {% if entry.uri == "__home__" %} 🏠 {% endif %}


3

For version 3.x.x. Check and get rebrand logo: {% if craft.rebrand.isLogoUploaded() %} <img width="{{ craft.rebrand.getLogo().size[0] }}" height="{{ craft.rebrand.getLogo().size[1] }}" src="{{ craft.rebrand.getLogo().url }}"> {% else %} Not set. {% endif %} Check and get rebrand icon: {% if craft.rebrand.isIconUploaded() %} <img ...


3

I'm going to guess something else is wrong in your templates, because all the examples you provided definitely work in Twig. Perhaps you have an error or typo on an earlier line that's preventing your imageHeight calculations from working. I'd also check what imageHeight is set to as that isn't apparent from the snippet you provided; you can check by dumping ...


3

I think you need to reference a macro name inside of your _common/_helpers file. For example: {{ helpers.input('username') }} That would output a macro called input: {% macro input(name, value, type = "text", size = 20) %} <input type="{{ type }}" name="{{ name }}" value="{{ value|e }}" size="{{ size }}" /> {% endmacro %}


3

.all() returns a collection of elements, which you can loop through with a for loop. .one() returns a single element, so you cannot use a for loop to access it. In this case you should just store the entry like: {% set entry = craft.entries.section('thing').one() %} and then access {{ entry.title }} afterwards. (Also keep in mind that entry is ...


3

Instead of duplicating the entries, you could run your entries loop twice (or as many times as you want) maybe? {% for i in 0..1 %} {% for entry in entries %} {{ entry.title }} <br> {% endfor %} {% endfor %}


3

When you call the |length twig filter you are implicitly treating the element query as an array. This behaviour was depreciated in Craft 3, and also results in a DB query being sent that is equivalent to .count() (Craft 3) or .total() (Craft 2). To remain up to date, while still minimising SQL load for your page: either call the relevant command (.count(), ...


3

Maybe it feels over the top, cause you could simplify your small request to something like this: {% for page in craft.entries.section('about').all() %} <h1>{{ page.title }}</h2> <p>{{ page.summary }}</p> {% endfor %} Or, if you just want to get the title and the summary of that one single - you could archieve this via: {% set ...


3

Definitely possible; you'd need to write a plugin or module in PHP to do it though. Probably it could listen to for the View::EVENT_BEGIN_PAGE event, and get the injected element via $element = Craft::$app->urlManager->getMatchedElement() Something sorta like this: use craft\web\View; // ... $request = Craft::$app->getRequest(); if ($...


3

So the way Twig works is that it populates a Twig Environment with a context of global variables. Then any time a template includes another template, the context is passed down to it. So if you want something to be globally available you have to insert it into the Twig environment before Twig is used, for it to be truly globally available. You can do that ...


3

There might be other ways, but here's one possibility: {{ craft.app.fields.getFieldByHandle('yourFieldHandle').className() }} This will return a string of craft\fields\PlainText, craft\fields\Lightswitch etc, which you can then use in conditionals/switch statements.


3

You are asking about Twig's operator precedence: The operator precedence is as follows, with the lowest-precedence operators listed first: ?: (ternary operator), b-and, b-xor, b-or, or, and, ==, !=, <=>, <, >, >=, <=, in, matches, starts with, ends with, .., +, -, ~, *, /, //, %, is (tests), **, ??, | (filters), [], and .: | is higher ...


2

Not sure about model, but you can return raw, unescaped value from plugin variable like this: use craft\helpers\Template as TemplateHelper; class someClass { public function someFunction() { return TemplateHelper::raw($some_values); } }


2

Was running into the same problem today. I was able to access the controller and the service, but none of the variables. Looks like Brad was able to fix the problem but didn't add a final solution. I wasn't registering any variables on the init() function. Adding the last line of code registered the variable but did not load it onto every request. // ...


2

This can be done like so... {% set matrix = craft.app.fields.getFieldByHandle('myMatrixField') %} {% for field in matrix.blockTypeFields if field.handle=='myDropdownField' %} <select> {% for option in field.options %} <option value="{{ option.value }}">{{ option.label }}</option> {% endfor %} </select> {% ...


2

Got this solution from Andrew Welch/nystudio107 over on Discord: Query for ':notempty:' in the URI, for example: craft.entries().uri(':notempty:').all() Docs: ':empty:' and ':notempty:'


2

You could use this variable to get the template name: {{ _self.getTemplateName() }} Put it at the top of all your template files: <!-- {{ _self.getTemplateName() }} --> And then for every template called it should have the commented out template name. In Craft 3, there's a nice plugin called "Template Comments" which is great for this... But I don'...


2

This doesn't work for every project, but for brochure style sites I like having all the client-arrangeable pages in one Structure, with toggles on each entry to optionally show in primary or secondary navigation, and Entry Types for different requirements such as a team page or articles section, and reserving Singles for things like homepage, privacy policy ...


2

Not sure how this would affect your docker set up, but this thread discourages the use of @web in your Base URL field. As the thread and @marten-brosch suggested, set the DEFAULT_SITE_URL in your .env file and use this variable in the Base URL field in the CP. For me, the live preview wasn't working because my site is secured with SSL but my ...


2

I needed to set the base-url to @web in: Settings > Websites > "your Website" > base-url This helps on my local docker-environment. Make sure, that your DEFAULT_SITE_URL="domain.something" is set in your .env file and that you are using the latest 3.2.x version.


2

Primarily, this is a Javascript question, not a Craft CMS question. For the Javascript part of this, I would look for general AJAX tutorials or try searching on Stack Overflow. But rather than downvote this question as being off-topic, here are some things to help on the Craft CMS side of things. You can create a template to generate a chuck of HTML you ...


2

In Twig 2, _self seems to reference the name of the current template file. Running {{ dump(_self) }} from the file /templates/test/index.twig would return the string test/index. So what it's being used for in this example... {% if craft.app.request.segments|last == _self %} ... is to test wether the last segment in the URL matches the template file. Or "...


2

profile.cpEditUrl is what you're looking for.


2

Unless I'm misunderstanding, the title of your question is a bit misleading as you're not trying to call a Craft function in Twig, you're trying to output a dynamically named variable (a variable variable). You can generally do that using the array syntax: e.g. categories[catOption].


2

I'm not entirely clear what your Matrix blocks/fields are setup like, so it's a little hard to tell what's going on here. But I'm going to take a stab at it. Your outer loop is looping through all the blocks in the calendarGroup Matrix field. Then you're using a switch to determine which piece of code to execute based on which one of the two block types ...


2

Two things I'm noticing about your code snippet: You'll want to use POST per the Mandrill API docs. All API calls should be made with HTTP POST. The options object should only contain valid Guzzle request options (key is not an actual request option); I think what you're trying to do is pass your key parameter in the request body. There are multiple ...


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