Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression to Change the words in part of a text layer?

  • Expression to Change the words in part of a text layer?

    Posted by Joshua Williams on March 8, 2025 at 5:38 pm

    I’m creating a MOGRT for a graphic that has a bunch of copyright and legal copy on the bottom. I need to enable it so that editors can change just a portion of one of the lines

    “© 2025 XYZ Corp. All Rights Reserved. YYY-ZZ-XXXXX”

    I need the editors to be able to change the YYY-ZZ-XXXXX part. What I’ve been doing is just having two text layers, one with the non-changeable line and one with the editable line and just putting the source text of the editable line in the MOGRT. It works but sometimes the length of the second line is longer or shorter and I added a position property so the editor can nudge it into the right place. I feel like it could be cleaner/simpler.

    So I’m wondering if there is a sourceText expression that will allow for changing just the YYY-ZZ-XXXX part if everything is on one text layer

    Roland R. kahlenberg
    replied 6 days, 7 hours ago
    3 Members · 7 Replies
  • 7 Replies
  • Joshua Williams

    March 8, 2025 at 6:45 pm

    figured it out with this –

    // Original text

    var originalText = “© 2025 XYZ Corp. All Rights Reserved. YYY-ZZ-XXXXX“;

    // Substring to replace

    var substringToReplace = “YYY-ZZ-XXXXX“;

    // Layer to Replace From

    var otherLayer = thisComp.layer(“REPLACE TEXT”);

    // New substring

    var newSubstring = otherLayer.text.sourceText.value.substring(0, 50);

    // Replace the substring

    var newText = originalText.replace(substringToReplace, newSubstring);

    newText;

  • Yoan Boisjoli

    March 9, 2025 at 2:19 pm

    Hey Joshua!

    If you’re looking for an easier solution, here’s what I usually do (see the screenshot as well):

    I create invisible text layers that are included in the Essential Graphics panel for editors to modify. These text layers are then assembled and linked to the main visible text layers. Here’s what the expression looks like:

    var year = thisComp.layer("Year").text.sourceText; //linking the text layer for the year
    var endTxt = thisComp.layer("End text").text.sourceText; //linking the text layer for the end part
    "© " + year + " XYZ Corp. All Rights Reserved. " + endTxt //assembling everything together

    in this case, I have a text layer for the year and one for the ending like in your case. so that way, the year can also be adjusted.


    Let me know if you got any questions !


  • Roland R. kahlenberg

    March 18, 2025 at 7:20 pm

    I like using Template Literals – so, my solution would look like this –

    const baseText = text.sourceText;

    const addText = thisComp.layer(“add Text”).text.sourceText;

    ${baseText} ${addText}

  • Yoan Boisjoli

    March 18, 2025 at 7:26 pm

    Hey Roland!
    I don’t think After Effects expressions support modern JavaScript template literals. because they use an older version of JavaScript (specifically JavaScript 1.2).
    Instead, you can achieve the same result using standard string concatenation methods. Here’s how you would rewrite your expression in After Effects:

    var baseText = text.sourceText;
    var addText = thisComp.layer("add Text").text.sourceText;
    baseText + " " + addText
  • Roland R. kahlenberg

    March 18, 2025 at 7:34 pm

    I’ve been using Template Literals for years, in After Effects.

    You may be confused between ExtendScript which requires ECMA 3 compliance and the After Effects Javascript Expression Engine which supports quite a fair number of Modern Javascript.

    More Info here –
    https://helpx.adobe.com/after-effects/using/expression-language-reference.html

    It does state – On Windows, After Effects uses the V8 open-source JavaScript engine.

    I’m now wondering what the difference is on macOS.

  • Yoan Boisjoli

    March 19, 2025 at 7:58 pm

    Hey Roland,

    I checked out the link you shared, and you’re absolutely right that After Effects’ expression engine supports modern features like let and const. Unfortunately, template literals (${} syntax) aren’t part of the supported features, at least not yet.

    If you’ve found a workaround or a unique method where template literals actually work, I’d be super curious to hear about it! Always happy to exchange ideas.

    Cheers!

    Yoan

  • Roland R. kahlenberg

    March 20, 2025 at 3:09 am

    I’ve been using Template Literals in AE for years and so have others.

    What happens when you try it on your system? Do you get any specific error or a silent exit/non-display?

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy