7

Is it possible to override the publishpath of a structure group?

I am using an AddBinary method by specifying a SG to publish to a location. Tridion publishes my binary under "Publication Path\SG path". But I want to override the publication path to something else.

In other words, I want to publish binaries / images to a particular publication path, which is different from the path mentioned in Publication's 'Publication Path' property.

Following is the exact scenario

1) I have a content publication C020 for desktop content and site publication S070 for Desktop pages. The publication path is \xyz 2) I have a mobile content publication C050 for mobile content and mobile site publication S072 for mobile pages. The publication path in S072 is \xyz\mobile

My requirement is whenever a binary is published from S070 & S072 my binaries always should go to a path \xyz.

If i used AddBinary with SG as parameter, i can not achieve the above. Because all my binaries published from S072 will always go to \xyz\mobile. Is there a way to publish the binaries to \xyz ?

4 Answers 4

8

You may specify any existing SG in your website publication in the AddBinary method. You may not, though, change the path of an existing SG. It's not a property you can set. An image must be associated with an existing structure group. However, you choose what SG you publish a binary to in your TBBs. So what you can do is call the AddBinary method with any SG that you have.

If you want to specify an SG that has the same path as the Folder that the image is in, then you can add logic to check if such as SG exists, and if not, create the SG based on the Folder path.

Here is a sample method that checks for an existing SG based on the a given Folder:

protected StructureGroup GetStructureGroupBasedOnFolder(Folder folder)
{
  Logger.Debug("Entering method GetStructureGroupBasedOnFolder");
  string folderWebDavUrl = folder.WebDavUrl;

  //Get the folder's relative path excluding "Building%20Blocks/Content"
  int indexOfRootFolder = folderWebDavUrl.IndexOf("Building%20Blocks/Content");
  string firstPath = folderWebDavUrl.Substring(0, indexOfRootFolder);

  string relativeFolderPath = folderWebDavUrl.Replace(firstPath + "Building%20Blocks/Content", 
                                                      string.Empty);
  Logger.Debug("relative folder path=" + relativeFolderPath);
  Publication pub = folder.ContextRepository as Publication;
  string pubSGWebDavUrl = pub.RootStructureGroup.WebDavUrl;

  string publishSGWebDavUrl = pubSGWebDavUrl + relativeFolderPath;
  Logger.Debug("publish SG webdav url=" + publishSGWebDavUrl);

  StructureGroup sg = m_Engine.GetObject(publishSGWebDavUrl) as StructureGroup;
  Logger.Debug("Returning from method GetStructureGroupBasedOnFolder");
  return sg;
}

You may also be creative on the CD side. For example, implement a custom storage extension that puts your images in a CDN and specifies their path. Will has written a nice high-level article about CDN publishing here: http://www.tridiondeveloper.com/some-thoughts-on-cmscdn-integration

1
  • Thanks Nickoli. I edited my questions to be bit clear. I already have the logic you mentioned but that doesn't satisfy my scenario.
    – vinoth
    Commented May 10, 2013 at 17:29
4

In the publication properties of S072 (right click on pub and go to Properties) update the Images Url field to /xyz instead of /xyz/mobiles so that it matches what S070 has.

Make sure to republish all content and pages that use the images to get the new paths.

1
  • And update the images path to be same as for S070...
    – Will Price
    Commented May 13, 2013 at 8:37
3

You can do one thing. Create a new structure group where you want to publish the images. Then, in the folder where the images are kept, edit the folder's metadata to store the the id of the structure group where you want to publish the images.

1
  • 1
    This does address the question on changing the path, though I'd recommend a relative WebDAV path over hard-coded TCM identifiers. :-) Commented May 10, 2013 at 17:18
3

Vinoth, it would help if you could explain also why exactly you have this requirement - as it seems a little bit strange, what is wrong with the mobile publication having its own binaries?

Firstly, if you are publishing from 2 publications to the same target folder, you need to be very careful that the binaries you publish have unique filenames, otherwise binaries could be overwritten or even removed in an unwanted manner. Chris Summers has a good blogpost explaining how to ensure this here

Presumably this is not behaviour that you want for all binaries in the mobile publication (otherwise you could just set the multimedia path and url for this publication to be the same as for the web publication and you are done - as Nicks answer shows), so there is some characteristic of the binary which determines that it should go to a separate location. If this characteristic is file extension (for example, all .pdf files should go to this same location) then you could potentially solve this with storage configuration and symlinks (for a UNIX deployer).

You can create a line in your storage config to map particular file extension(s) to a separate file location, and create a symlink from this location to the xyz folder.

<Item typeMapping="Binary" itemExtension=".pdf" storageId="specialMobileBinaryFiles" cached="true"/>

I have to admit I never actually did the symlink bit of this before, but it should in theory be possible. Probably there is some kind of symlink equivalent in Windows - google should be able to help you there. If you do try this, let me know if it works!

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.