Replacing image URL in WYSIWYG content

diekema's Avatar

diekema

02 Dec, 2014 06:24 PM

Hi! I've been attempting to change (using velocity) some content from the WYSIWYG editor.

I need to have the full URL for the image appear in the final page. I can get the full path, but not the site name. I've attempted to use .replaceAll to add it in, but for some reason it strips out the "http:"

Is there a better way? I'm guessing some of my problems are due to the image src being rendered at a different time then the velocity transformation?

Thank you!

  1. 1 Posted by Ryan Griffith on 03 Dec, 2014 01:51 PM

    Ryan Griffith's Avatar

    Hi,

    When you access the WYSIWYG content using either an Index Block of the Locator Tool, you should see the full path to the image which includes the site://SITE_NAME prefix. When you have a moment, please attach your Velocity Format so we can get a better sense of where things are at.

    Thanks!

  2. 2 Posted by diekema on 03 Dec, 2014 04:23 PM

    diekema's Avatar

    Ahh maybe I'm going at this wrong. Attached is my velocity format

    #set($groups = $_XPathTool.selectNodes($contentRoot, '//email_articles')) 
    
    #foreach ($child in $groups )  
    
            <a name="$foreach.count"></a>$child.getChild('article_title').text</h3>
        
        #set ($x = ${_SerializerTool.serialize($child.getChild('article_content'),true)})
        #set ($x = $x.replaceAll("<a","<a style='color: #78a22d; text-decoration: none;' ").replaceAll('src="/programs','src="http://www.edwards.usask.ca/programs'))
      
        $x
    #end
    
  3. 3 Posted by Ryan Griffith on 19 Jan, 2015 04:26 PM

    Ryan Griffith's Avatar

    Hi,

    My apologies for the delayed response to your discussion, I was going over some older discussions and noticed this one is still open. Were you able to work through your path replacement issue?

    Please feel free to let us know if you have any other questions.

    Thanks.

  4. 4 Posted by diekema on 19 Jan, 2015 08:53 PM

    diekema's Avatar

    I was! I was turning the content into a serialized string. When I was using replace to change the text, it would work for changing the attributes for a hyperlink no problem.

    For Example

    #set ($x = $x.replaceAll("<a","<a style='color: #78a22d; text-decoration: none;' "))

    But if it was a URL ( I wanted to put the full absolute URL in there as this was an email template) it would fail or give very strange results.

    What was happening is the serialized text would contain “site://nameofsite/the url” and it was causing the replace to not work.

    But the CMS would format the text at the end and strip the site:// text. So I would never see it. Once I figured that out, I just include it in the replace and voila it works!

    Thanks!

  5. 5 Posted by Ryan Griffith on 19 Jan, 2015 09:01 PM

    Ryan Griffith's Avatar

    Thank you for following up and the additional information on your findings. I am glad to hear you were able to work things out.

    I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.

    Have a great day!

  6. Ryan Griffith closed this discussion on 19 Jan, 2015 09:01 PM.

Discussions are closed to public comments.
If you need help with Cascade CMS please start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

 

26 Aug, 2016 01:19 PM
25 Aug, 2016 03:02 PM
25 Aug, 2016 12:50 PM
24 Aug, 2016 08:43 PM
24 Aug, 2016 07:20 PM
21 Aug, 2016 01:20 PM