Try our conversational search powered by Generative AI!

How to get the absolute URL of each item in content in the ContentRendere

Vote:
 

How to get the absolute URL of each item in content in the ContentRendere?

We want to send the images or links in the email. Which is a contentare on a page. When we send the email the image doesn't show up. Is there a way to get the absolute URL of each item in the content in the rendere method?

Thansk!

#118146
Feb 28, 2015 0:00
Vote:
 

Hi,

If your'e using a page as an email template, I would run the whole ouput through a filter which then rewrites all URLs to absolute. Or you can hook into the URL rewriter:

[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class DataInitialization : IInitializableModule
{
    public void Initialize(InitializationEngine context)
    {
        Global.UrlRewriteProvider.ConvertingToExternal += this.RewritingToExternal;
    }

    public void Uninitialize(InitializationEngine context)
    {
        Global.UrlRewriteProvider.ConvertingToExternal -= this.RewritingToExternal;            
    }

    public void Preload(string[] parameters)
    {
    }

    private void RewritingToExternal(object sender, UrlRewriteEventArgs e)
    {
        // Check if the current page is an email template
        var pageIsEmailTemplate = true;

        if (pageIsEmailTemplate)
        {
            e.Url.Host = "www.example.com";
            e.IsModified = true;
        }
    }
}

All links, image urls and so on will have absolute URLs with the host www.example.com.

#118148
Feb 28, 2015 1:34
Vote:
 

Hi Johan,

We are using Content Areas in the email templates. Using MVC postal to send views based emails. 

The model for the email view is generated on the fly from an existing page that contains content areas. When we drop contents (block, images) in the content area, by default it gives the path the image to be relative. Is there a way to change that to absolutel. 

Thanks,

Syed

#118352
Mar 04, 2015 17:30
Vote:
 

Yes, by having a filter that rewrites the whole output. It will take care of all URLs, not just the ones from your content area.

Your other option is to concatenate the realtive URL with a host, manually, for every item in your content area.

#118353
Mar 04, 2015 17:44
Vote:
 

Can you use Tags for showing email-friendly templates?

Have a look at Alloy website and tags.

#118358
Mar 04, 2015 19:14
Vote:
 

Sounds good. It would be greate if you could provide a sample code snippet or link that we can get an idea from. The issue I am facing is that the email page is not being generated by the controller but just by calling the "FindPagesWithCriteria" method. Can we still use the filter on the page object? 

Thanks,

Syed

 

#118359
Mar 04, 2015 20:18
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.