user-pic

Macro for Web site URL

Vote 0 Votes

Hi All,

I'm in the process of upgrading to MT 5. I'm doing the upgrade in a staging area which is a subdomain of my site. I'm taking advantage of the upgrade to clean things up and reduce the clutter that's accumulated over the years. To this end, I need to rearrange where images and other resources are stored. I want to make sure this works in the staging area before switching over to my production site. Because of this, I need the URLs in the blog entries to use the proper domain (http://staging.mysite.com or http://mysite.com). I thought I could update the URLs to something like "images/whatever.png." However, I can't find a macro for the domain name itself. is there one? If not, how are people handling this sort of thing?

TIA!

--

Regards,

Travis Spencer

Reported on Movable Type 5

5 Replies

| Add a Reply
  • Hi Travis,

    If you're talking about creating URLs that reference images, then I think you should be able to use URLs that explicitly *don't* reference the domain.

    So if there's a folder at the top level of your website called images and a file called header.jpg in it, you can use:

    <img src="/images/header.jpg">

    and that will work both on your staging server and in production.

    If there's something more complicated going on that I'm not aware of and you really do need to include the domain of the site, then you should be able to use:

    <mt:blogURL/>

    And this will output the "root" URL of the blog, as you've defined it in Preferences->Publishing

    Hope that helps...

    -tony

  • Thanks, Tony, for the reply; however, using server-relative paths (e.g., "/images/...") will cause the links to not work in feeds. Also, <mt:blogURL> won't let me access a directory right below the root of the domain. I want to put all images for all my pages and blog posts (for all three of my blogs) in the same directory (i.e., "http://.../images" not "http://.../blog1/images" and "http://...blog2/images"). As a result, I'd have to do "<mt:blogURL>../images" which is tacky at best.

    Any other ideas?

  • I understand the new MT5 has blog-level Custom Fields... I'm not on MT5 myself yet, so I can't vouch for this.

    I've done a workaround because I needed blog-level custom fields in MT 4. Create a global template module, e.g. "Settings"

    inside, you can put:

    <mt:var name="ImageRoot" value="http://staging.domain.com"/>

    Then, be sure to include this module wherever you need it, ideally in a spot that's already being included -- for instance, you could include it in a common Header template:

    <mt:include module="Settings"/>

    Come to think of it, since in your case you want the same value for all blogs, you could simply set the ImageRoot variable in a global header template, if you have one.

    The approach I've mentioned came in handy when there were settings that actually changed from one blog to another. (Again, really just a hack workaround for the lack of Blog Custom Fields).

    This is really akin to using #include or similar constructs in more formal languages. In MT, we're kind of trained to use includes for chunks of HTML, but it can be helpful to think of using them for code constructs or variables as well.

    -tony

  • Your suggestion sounds like it will work, Tony, so I'll try that. If I hit any snags, I'll post back here.

    Thanks for the help. It's much appreciated.

  • Thanks for sharing the great solution

Add a Reply

If you need to share template code, replace all the "<" signs with "&lt;" or use this utility.

Forum Groups

1773 6162

Last Topic: Excluding categories from blog by kholechek on Feb 9, 2012

86 302

Last Topic: website entries by masoud on Oct 26, 2011

1429 5077

Last Topic: What apocalypse hit this community in the middle of 2011? by 75th on Feb 10, 2012

694 2908

Last Topic: Blogspot to Movable Type by sdude on Feb 8, 2012

84 291

Last Topic: How to have some other characters in entry basename automatically written by Afshin Haghighatnia on Dec 22, 2011

173 737

Last Topic: About the MT version stated in HTML source by Alex E. Schneider on Feb 7, 2012

190 565

Last Topic: Analytics Reporting by michael webster on Feb 5, 2012

48 210

Last Topic: An idea and also a request by Afshin Haghighatnia on Jun 29, 2011

64 246

Last Topic: jQuery in MT 5.1 still at 1.4 - why? by perlmonkey on May 25, 2011

code.sixapart.com

137 478

Last Topic: Getting a thumbnail with xpath by Peter on Mar 13, 2011

222 720

Last Topic: Custom Field for Asset Not Appearing by android on Feb 9, 2012