megatrond
  • Member for 7 years, 2 months
  • Last seen more than a month ago
Getting logged out of admin area when refreshing site
Accepted answer
10 votes

The problem was actually Chrome using iOS emulation when viewing the site, thus spoofing the UA string into something different than the usual Chrome UA string when logging into the admin area. ...

View answer
Is it possible to have entries only visible to logged-in users?
8 votes

Yes. You need to build a frontend login form and then block non logged in users from seeing the entries with something along the lines of this: {% if craft.session.isLoggedIn %} {# put content ...

View answer
twig for loop put every 2 elements in a new container
8 votes

I usually do this like so: {% for block in blocks %} {% if loop.index0 % 2 == 0 %} <div> {% endif %} {# other stuff #} {% if loop.index0 % 2 == 1 or loop.last %} </div> ...

View answer
Fetch all unused assets?
Accepted answer
7 votes

With good help from @carlcs here and on Slack, we found a solution: {% set allEntryIds = craft.entries.limit(null).ids() %} {% set usedAssets = craft.assets({ relatedTo: allEntryIds, limit: ...

View answer
What is the best way to append CSRF token without using a form?
Accepted answer
5 votes

You need to pass the token and name into javascript. Easiest is to just have a script tag somewhere. <script type="text/javascript"> window.csrfTokenName = "{{ craft.config.csrfTokenName }}"...

View answer
How to compare just the date part of a dateTime field?
Accepted answer
5 votes

I'm not 100% sure I'm reading your question correctly, but here goes: I'm assuming you're getting the date as a string as a route param (maybe you shouldn't call it date though, as that is a function ...

View answer
Make exponent style in Riche Text field
5 votes

In craft/config/redactor you can either add your own setting file, or edit one of the ones already there. If you add the following JSON: "formattingAdd": [ { "tag": "sup", "title": "...

View answer
How to handle license when duplicating entire website
5 votes

I think it would be enough to delete the license.key file under craft/config and purchase a new license. The key file will be re-generated. Some more info in this answer, and here is how Craft ...

View answer
Old Posts Not Appearing in XML Sitemap
Accepted answer
4 votes

Default limit is 100, try adding .limit(null) to the query

View answer
Is there a way to divide an entry's data into multiple subviews with unique URLs?
Accepted answer
4 votes

Disclaimer: I haven't ever used structure, but hopefully the method described below also works for that section type. You can do this quite easily with URL-segments Consider a URL like so: http://...

View answer
using cycle with unknown number of entries
Accepted answer
3 votes

This is how I usually solve this problem, notice the explicit check for the last element in the list. You can set cols to whatever number of columns you want. {% set cols = 4 %} {% for thing in ...

View answer
Entry URIs incorrect when using entriesService->saveEntry()
Accepted answer
3 votes

Ok, so the answer was quite simple: I was using the PHP DateTime object instead of Crafts DateTime. Removed the \ on this line: $date = new \DateTime($article['article_start'], new \DateTimeZone('...

View answer
Is it possible to create a cleaner replace?
Accepted answer
3 votes

I'm just gonna post my comment as an answer, because I think it's the way to go. I'd use the kebab filter instead of url_encode, like this: {jobTitle|kebab}

View answer
List Categories AND their associated entries
Accepted answer
3 votes

Something along the line of this should do that: <ul> {% for category in craft.categories.group('categoryGroupHandle') %} <li> {{ category.title }} {% for entry in ...

View answer
How do I set up PhpStorm for plugin development
Accepted answer
3 votes

I point File->Open Directory at craft/.., and PhpStorm pick up everything for me. You probably have to set up path mappings to make debugging work properly, but PhpStorm will alert you to that and ...

View answer
How do I use dynamic variables for plugin settings?
Accepted answer
3 votes

First - you don't need a template file. You can type the template right into the settings textarea like you already had, and like the other email twig templates do it. Then, in your service, you do: $...

View answer
Multi domains in Craft 2 licensing
2 votes

As long as the control panel is only accessible from one domain, I'd say you're within the license requirements. example.com and example.fr are different domains, and really no less different than ...

View answer
Set Craft variables in the markup
Accepted answer
2 votes

Just use a variable that has the same keys as the entry model will have. {% set entries = [{title: 'hello', ...}, {title: 'hello2', ...}] %} {% for entry in entries %} {# stuff #} {% endfor %} ...

View answer
Structure(s) vs. Categories for product catalog
2 votes

I find it difficult sometimes to choose between a category group and a structure, so for me it mostly boils down to semantics. A brand can be both a structure entry and a category. If you're going to ...

View answer
Can't get locales to work properly
Accepted answer
2 votes

Have you tried putting da_dk in as the key in the siteUrl array?

View answer
Images uploaded or static
2 votes

Can't speak for anyone else, but I have an img and a fonts directory in my public directory, where I put static image files and fonts. One positive about putting it in the assets is that you have ...

View answer
Changing the order of an 'archive' page
Accepted answer
1 votes

If you change your query and sort by ascending postdate, it will start with the oldest and end with the newest: {% set entriesInYear = craft.entries.section('blog').limit(null).after(year).before(...

View answer
Element API plugin - Return message when no results are found
1 votes

This is definately a sub-optimal workaround, but it might work: Have your criteria in the api config fetch something you know is there, and there is only one of - your homepage or a global set (maybe ...

View answer
How to show multiple calendars
Accepted answer
1 votes

Posting comment as answer, since the suggested solution solved it: Pass the IDs as an array instead of comma separated: {% set thisCalendar = [3,2] %}

View answer
Dynamically load either standard res or hi-res background image
1 votes

This is actually a difficult problem, and there are many possible solutions, none of which are optimal (until img srcsets are better supported). The way I would probably go about doing this, depends ...

View answer