3

I am using this code in a TBB to build links to multimedia items:

imageBaseUrl = new Publication(_engine.GetSession()).MultimediaUrl;

I assumed that Publication.MultimediaUrl would return "/Multimedia", which is the value for the 'Images URL' in Publication > Properties > General. Instead it returns "/Images".

So two parts to my question:

  1. How do I retrieve the value specified in 'Images URL'
  2. How/Where do I specify a value for 'Publication.MultimediaUrl'? (or "Where is this "/Images" string coming from?")
1
  • I've noticed that "/Images" is the default for that field, so all parent publications have Image URL set to "/Images". Is it possible that Publication.MultimediaUrl is getting a value from a parent publication? maybe the publication the TBB is defined in?
    – Joe
    Commented Dec 11, 2013 at 5:34

2 Answers 2

2

You are loading a new Publication instead of an existing Publication which is why you do not see the path expected (but get the default path, being /Images).

Instead of using:

imageBaseUrl = new Publication(_engine.GetSession()).MultimediaUrl;

use:

TcmUri pubUri = new TcmUri("tcm:0-35-1");
imageBaseUrl = new Publication(pubUri, _engine.GetSession()).MultimediaUrl;

Where tcm:0-35-1 is the TCM URI of the Publication you need the Multimedia URL from.

Depending on where you are using this code (Page or Component Template), you could also get the Publication from the Template item using something like this:

RepositoryLocalObject item;

if (package.GetByType(ContentType.Page) != null)
{
    Item pageItem = package.GetByType(ContentType.Page);
    item = (Page)engine.GetObject(pageItem.GetAsSource().GetValue("ID"));
}
else
{
    Item componentItem = package.GetByType(ContentType.Component);
    item = (Component)engine.GetObject(componentItem.GetAsSource().GetValue("ID"));
}

if (item != null) 
{
    Publication publication = (Publication)item.ContextRepository;
}

The Templating Base Project on SDL Tridion World has a lot of useful methods for getting current objecta like the Page or Component you are rendering in the Template and their Publication. When including that in your TBB project, you can simply use a method like GetPublication().

3

The /images link is configured in your publication settings.

Have a look at the addbinary method in the Tom.net api, this publishes the binary and returns the URL that will be used in the published website, it also ensures the file is deployed with the content when publishing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.