ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

One single Global Variables for PATH on Images

January 22, 2012 11:41am

Subscribe [4]
  • #1 / Jan 22, 2012 11:41am

    Mario Rodríguez

    72 posts

    Hi,

    right now I do this to tell the template the url where to grab de image:

    I create a Global Variable with the URL Path:

    http://web-ejemplo.com/themes/site_themes/web/

    {Url_IMAGENES}

    And then I embed that Global Variable in every <img= > 
              <div id=“header-social-icons”>
                  <ul>
                    <li>{Url_IMAGENES}images/icons/social-from-iconsweets/twitter.png</li>
                    <li>{Url_IMAGENES}images/icons/social-from-iconsweets/facebook.png</li>
                    <li>{Url_IMAGENES}images/icons/social-from-iconsweets/gplus.png</li>
                    <li>{Url_IMAGENES}images/icons/social-from-iconsweets/vimeo.png</li>
                    <li>{Url_IMAGENES}images/icons/social-from-iconsweets/youtube.png</li>
                    <li>{Url_IMAGENES}images/icons/social-from-iconsweets/flickr.png</li>
                    <li><div id=“header-search”>
                          <input type=“text” name=“Search” id=“search” placeholder=“Search the site”>
                          <input type=“submit” name=“Go” id=“go” value=“Go”> 
                      </div>
                    </li>
                  </ul>
              </div>
            </div>
            <!—TOP ELEMENTS ENDS—>

    Is there a more efficient way of doing this?

    Like setting it somewhere in CP or setting a Global Path at the beginning of the template or so?

    BTW, can you embed Global Variables within Global Variables or is better use templates with Global Variables and embed those templates y other templates?

    Thanks

  • #2 / Jan 22, 2012 6:02pm

    stinhambo

    1268 posts

    Why don’t you put all your assets in a folder called assets so the full path is -

    http://web-ejemplo.com/assets/images/icons/social-from-iconsweets/

    That way you only need to refer to them as /assets/images/icons/social-from-iconsweets/your-image.png

  • #3 / Jan 22, 2012 6:32pm

    Mario Rodríguez

    72 posts

    It is so.

    But I thought I could define a kind of relative path variable or so, I didn’t I had to use full paths URLs to access images from templates.

  • #4 / Jan 23, 2012 11:30am

    Andrew Fairlie

    126 posts

    Is there a more efficient way of doing this?

    BTW, can you embed Global Variables within Global Variables or is better use templates with Global Variables and embed those templates y other templates?

    Your solution sounds fine, you could alternatively use preload variables but I think your idea follows DRY a lot better.

    I believe you can embed within snippets. In case you aren’t familiar snippets can be thought of as a middle-ground between Global Variables and Templates:- http://ellislab.com/expressionengine/user-guide/templates/globals/snippets.html

    Snippets are small bits of reusable template or tag parts. You could create a Snippet for any number of purposes, anywhere that you need to reuse a small portion of a template, including partial or complete tags, other variables, etc. Snippets add flexibility and reusability, while making it simple to make site-wide changes by editing the Snippet’s source instead of having to modify many templates.

  • #5 / Jan 23, 2012 4:38pm

    Kevin Smith

    4784 posts

    Thanks for the suggestions, all.

    Mario, my own recommendation would follow along the same lines as that of Steven Hambleton, though as with lots of things in web design, there are many routes you can legitimately take. Have you found a solution that works best for you?

  • #6 / Jan 23, 2012 5:40pm

    Mario Rodríguez

    72 posts

    I use Global Variables to embed HTML code and Snippets to reuse code with exp tags.

    I must say I got crazy trying to find out how to tell a template where to grab the images. As I did not know what EE considerar the relative path (I was still thinking from a relative path/file perspective) I did not find anything in the documentation or EE ebooks about this.

    So I came to the conclusion there is not relative path, you have to tell the template the complete path url where the image is, and the best way I found is embeding the path url within a global variable and write that global variable this way on the image url:

    path={global_variable_name}/image/image_example.jpg

    I thought there would be a way to tell EE within a template where the files are, a kind of declaring a global url path or something like at the beginning of the template:

    relative_path=”{/web/themes/myweb/}

    So that it wouldn’t be necessary to do all this…

     

  • #7 / Jan 29, 2012 1:00pm

    Sean C. Smith

    3818 posts

    Mario,

    I too use the exact approach that Steven Hambleton uses. It looks like you’ve found a solution that is working for you though. Is there anything else I can assist you with?

    Sean

  • #8 / Jan 29, 2012 1:21pm

    Mario Rodríguez

    72 posts

    Sean,

    It’s ok.

    Thanks for your help

    Mario

  • #9 / Jan 31, 2012 7:05pm

    Sean C. Smith

    3818 posts

    Mario,

    Glad that everything is good now. I’m going to close out this thread, but feel free to post again when you have more questions.

    Sean

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases