<p>One thing that might help is to use the Ternary Operator described here:</p>

<p><a href="http://twig.sensiolabs.org/doc/templates.html#other-operators" rel="nofollow">http://twig.sensiolabs.org/doc/templates.html#other-operators</a></p>

<p>Example:</p>

<pre><code>{{object.mfgCategory.first.slug=="1hack"?'hack':mfgCategory.first.slug}}
</code></pre>

<p>instead of:</p>

<pre><code>{%if object.mfgCategory.first.slug=="1hack"%}hack{%else%}{mfgCategory.first.slug}{%endif%}
</code></pre>

<p>It's slightly shorter so might help a bit.</p>

CC BY-SA 3.0
2015-04-23T21:07:17.067Z
2015-04-23T21:07:17.067Z
Lewis Jenkins
<p>You could refactor it using <a href="http://twig.sensiolabs.org/doc/templates.html#other-operators" rel="nofollow">ternary syntax</a> and see if it fits. Otherwise you could also do it with a plugin and listen to <code>beforeSaveEntry</code> events.</p>

CC BY-SA 3.0
2015-04-24T18:37:15.860Z
Thanks for the help! I used the ternary syntax and shortened some field handles to keep from having to use a plugin.
Chandra
CC BY-SA 3.0
2015-04-23T21:01:28.930Z
2015-04-23T21:01:28.930Z
carlcs
<p>I'm trying to set the URL of my product entry's to be dynamically created based on 3 category fields and 2 number fields. The category fields are required, but I need to add some logic for the number fields. </p>

<p>It's all taking up so much space that upon saving the section's settings, the URL Format field cuts off some of my code. I'm sure there is a great reason that this field has a character limit so is there anything else I can do? I tried importing a macro, but couldn't get that to work. Do I have to create a plugin?</p>

<p>This is the content I need to use in my Entry URL Format that is too long with my variable names:</p>

<pre><code>some-text-here/{%if object.mfgCategory.first.slug=="1hack"%}hack{%else%}{mfgCategory.first.slug}{%endif%}-{%for c in object.series%}{c.slug}-{%endfor%}{sizeCategory.first.slug}-{%if object.num1=='0'%}00{%else%}{number1}{%endif%}-{%if object.number2=='0'%}00{%else%}{number2}{%endif%}
</code></pre>

<control-panel><url><format>
My Entry URL Format needs are too long for the field restrictions
# My Entry URL Format needs are too long for the field restrictions

(Asked by: username_0 on 2015-04-23)

I'm trying to set the URL of my product entry's to be dynamically created based on 3 category fields and 2 number fields. The category fields are required, but I need to add some logic for the number fields. 
It's all taking up so much space that upon saving the section's settings, the URL Format field cuts off some of my code. I'm sure there is a great reason that this field has a character limit so is there anything else I can do? I tried importing a macro, but couldn't get that to work. Do I have to create a plugin?
This is the content I need to use in my Entry URL Format that is too long with my variable names:
some-text-here/{%if object.mfgCategory.first.slug=="1hack"%}hack{%else%}{mfgCategory.first.slug}{%endif%}-{%for c in object.series%}{c.slug}-{%endfor%}{sizeCategory.first.slug}-{%if object.num1=='0'%}00{%else%}{number1}{%endif%}-{%if object.number2=='0'%}00{%else%}{number2}{%endif%}

**Tags:** control-panel, url, format

---

## 2 answers

### Answer by username_1 on 2015-04-23. Score: 1 | Accepted answer

One thing that might help is to use the Ternary Operator described here:
http://twig.sensiolabs.org/doc/templates.html#other-operators
Example:
{{object.mfgCategory.first.slug=="1hack"?'hack':mfgCategory.first.slug}}

instead of:
{%if object.mfgCategory.first.slug=="1hack"%}hack{%else%}{mfgCategory.first.slug}{%endif%}

It's slightly shorter so might help a bit.


---

### Answer by username_2 on 2015-04-23. Score: 2

You could refactor it using [ternary syntax](http://twig.sensiolabs.org/doc/templates.html#other-operators) and see if it fits. Otherwise you could also do it with a plugin and listen to `beforeSaveEntry` events.

> **Comments:**
> **username_0**: Thanks for the help! I used the ternary syntax and shortened some field handles to keep from having to use a plugin.  

---

