31

TLDR; In general, my preference would normally be to use a snippet, unless I need the variable content to be user editable (eg site email), and to only use an embed when parse order issues or similar necessitate it. Here's why... Snippets: Snippets are frequently my first choice for implementing reusable code fragments in EE. They are parsed at a very ...


8

All three of these are used for enabling you to not repeat yourself when building sites, but they vary in functionality quite a lot. Global Variables Global Variables are used generally for storing pieces of content that might not be be part of an entry, for instance a contact form email address, a store address, etc. You can not use EE tags within a global ...


7

If the project has relatively low needs in terms of site-wide data (read, If you don't need custom fields), then I tend to store these in global variables and snippets. When I need to store more advanced content, I personally use low variables. Pretty much a default now on medium or big EE builds. You can then use custom fields like Matrix, Wygwam, playa, ...


7

As someone who has been using EE for years, and going about templating in exactly the manner you are trying to for those many years, and who is just now learning a much easier way, I would like to suggest you look into using Stash. The difference is that in the EE templating method you are pursuing, and that I and many others used for years is that your ...


7

Take a look at your main index.php file, you should see this line: // $assign_to_config['global_vars'] = array(); // This array must be associative Once that's uncommented and populated the variables should be available in your templates. For example: $assign_to_config['global_vars'] = array('analytics_key' => 'UA-XXXXXXX-XX'); That should be ...


5

The count variable is 1-indexed so you need to do {if count == 1}{/if} to get the first in a loop.


5

You should do this in an Extension instead - an extension on the sessions_end hook (which is called near the beginning of every request to the site, just after the Session library has finished loading). You could then create new Global Variables before any template parsing begins, and which would then be available to all of your templates. Extensions are ...


5

I always recommend my add-on Authenticate. https://objectivehtml.com/authenticate/documentation/tag/logout-url {exp:authenticate:logout_url return="/some/return/url"}


4

I think UltraBob is right in that if you need a global variable available inside the module you need parse them inside the add-on. parse_globals() looks to be the way to do so (thanks to this answer on Stack Overflow). The following will show that the parsed global is available in the module: $parameter = $this->EE->TMPL->fetch_param('...


4

The variable {ip_address} is one of the standard global variables that is parsed last, even after advanced conditionals. That means you can't use it in a conditional. You can use Mo’ Variables (or Low Variables if you’re already using it) to have {logged_in_ip_address} available as an early parsed var, so you can use it in conditionals.


4

So both of the above should done done relatively easy with the query tool... The SQL you'll need is : SELECT count(*) as active_members from exp_members WHERE FROM_UNIXTIME(last_visit) > DATE_SUB(NOW(), INTERVAL 30 DAY); The second one would just be : SELECT count(*) as active_members from exp_members where group_id=1 OR group_id=3 OR group_id=5; You'...


4

The issue is parse order. Read the attached pdf.parse order. Turn on the debugger and then view the template in your browser. Scroll down thru the debugger until you find the tag containing {current_url}. You will see that that {current_url} has not been parsed. According to the attached doc, it is not parsed until step 9 - last. In your module, try $...


4

Using the matches operator, which was added in EE v2.9.0: {if segment_2 ~ "/^\d+$/"} [...] {/if}


3

The issue is one of parsing order... User Defined global variables are the last thing to be parsed. This PDF outlines ExpressionEngine’s Parse Order. This page in the docs details the Rendering Stages of the EE template engine. The solution is to switch to using a Snippet instead.


3

Global variables declared in Design > Templates > Global Variables cannot contain EE tags, PHP, or other variables inside them. User-defined global variables are not run through the template engine, so you cannot place EE Tags, PHP, or variables inside them. If you need to place EE tags inside re-usable bits of code then you'll need to use Snippets: ...


3

I use a add-on for member management on the front-end called FreeMember. This add-on offers a more fine grained control for member management using regular templates. (including return url after logout). https://github.com/expressodev/freemember


3

I agree that this is a parse order issue. It would probably be better for you to set your global variable in the config.php. Not only will this ensure it's set before the templates are parsed, but it'll also prevent you from needing to use PHP in your template, which makes things a bit more secure and efficient. If you're using the Focus Lab Master Config, ...


2

I had this same issue yesterday and the facepalm moment was when I realized I had added my variable to config.dev.php when I should have added it to config.local.php. Are you certain it's not a similar situation? Perhaps double check the case statements in config.env.php to ensure the matching is working.


2

Angie, I looked through our config code and what you've done should work. Can you confirm that you're editing the right environment file to be sure? I'm reading this from my phone so when I get to my desk later I'll run a few tests to see what's up.


2

My suggestion would be to use Low Variables, which allows you to set parse order for your snippet effectivly letting you set it to be a global variable or a snippet. Additionally you can pass variables to a low variable as if it were an embed using preparse (unlike traditional snippets which can't have anything passed to them) - see this blog post for ...


2

Another option, besides FreeMember is LogIn Redirect. Generally speaking, the standard login/logout doesn't offer you much leeway in modifying redirects, but either of these plugins (and others) aim to improve that experience.


2

Why not use http://eeinsider.com/articles/multi-server-setup-for-ee-2/ as a basis and work from there?


2

As EE parses {ip_address} after advanced conditionals it easy enough to get that data parsed sooner. I haven't got Low Variables installed on this site otherwise I would use it. Instead you could add it as a variable to config.php: $config['ipaddress'] = $_SERVER['REMOTE_ADDR']; Or I've actually added to my bootstrap file but it achieves the same thing.


2

You're running into a parse order issue here. The conditionals are parsed before the global variables, and therefore your comparison is taking place with the actual value you have within the conditional instead of the parsed value. There are a couple things you can do. 1) Use a snippet instead of a global variable, as these parse much earlier 2) Use an ...


2

There are a number of approaches you could take. Here's one using native EE functionality We can see from the Twitter docs that we need the following markup: <meta name="twitter:card" content="summary"> <meta name="twitter:site" content="@nytimes"> <meta name="twitter:creator" content="@SarahMaslinNir"> <meta name="twitter:title" ...


2

First of all, the stylesheet tag needs quotation marks. {stylesheet="global_embeds/style"} If you link to the JS file using path variable, all the templates variables on the linked file will be parsed. {path="global_embeds/init.js"} But I really don't think it's good for performance. It's much better to use static links for the JS and CSS.


2

Create a plugin - don't do this in the template. Then you can do whatever you like in pure PHP (with access to all of EE's helper functions, libraries, etc), create a variables array, and then return it for use as template tags.


2

One really simple way to get around parse order is just to use an embed. {embed="embeds/_rest" ip_address="{ip_address}"} Then in your embedded template (embeds/_rest): {exp:rest url="http://domain.com/{embed:ip_address}" verb="get" format="json"} {/exp:rest} Embeds get a bad rap performance-wise, but as long as you aren't using them excessively or ...


2

Well the short answer is you can'tshouldn't easily, it raises all sorts of questions regarding the security model! However there may be alternatives. You could for instance write an extension for EE that exposes an ACTion (as Derek said), or more simply just write a template, and then get your information through AJAX/curl from your other external page. ...


1

Your best bet is to hold this URL via a global variable defined inside of your config file (as standard user-defined global variables will be scoped to each site). Or to get fancier, use Low Variables, which will may help you elsewhere in your site build as well.


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