Trouble with curly braces in Entry URL Format / renderObjectTemplate This works:

{{ craft.entries.section('products').relatedTo(object).first.uri }}/{slug}


However, in this case, I need to use the extended relatedTo property, which includes curly braces:

{{ craft.entries({relatedTo: {targetElement: object, field: 'productConfigs'}}).first.uri }}/{{ object.slug }}


Because of the way renderObjectTemplate replacement seems to happen, the braces get screwed up.

Any way to work around this?

I'd actually rather do this in PHP/plugin if possible, but I'm not sure if a relevant hook/event exists.
It's not documented so I guess not officially supported, but you can use template variables in the URL formats. For example if you had a UrlFormats plugin, you could use something like this:

&lt;?php
namespace Craft;

class UrlFormatsVariable
{
    // Use in the URL Format box:
    // 
    //  {{ craft.urlFormats.yourSectionHandle(object) }}
    public function yourSectionHandle($entry)
    {
        // Craft checks the URL format with an array "object" first, to see if there's a {slug},
        // and so whether it should be checked for uniqueness and incremented if necessary.
        if (!$entry || !($entry instanceof EntryModel))
        {
            return '{slug}';
        }

        $relation = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry)
            -&gt;relatedTo(array(
                'targetElement' =&gt; $entry,
                'field'         =&gt; 'productConfigs',
            ))-&gt;first();

        if (!$relation)
        {
            // throw an exception or default to something
        }

        return $relation-&gt;uri.'/'.$entry-&gt;slug;
    }
}


Then you can keep your URL Format and Nested URL Format inputs cleaner:

{{ craft.urlFormats.yourSectionHandle(object) }}