Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken Conditional with Statamic Upgrade from 3.0.8 to 3.0.9 #2456

Closed
LloydThinks opened this issue Sep 17, 2020 · 7 comments · Fixed by #2663
Closed

Broken Conditional with Statamic Upgrade from 3.0.8 to 3.0.9 #2456

LloydThinks opened this issue Sep 17, 2020 · 7 comments · Fixed by #2663
Labels

Comments

@LloydThinks
Copy link

LloydThinks commented Sep 17, 2020

Bug Description

Upgrade from 3.0.8 to 3.0.9 breaks working code. In particular, it breaks an Antlers If statement:

{{ if "test" !== "test" and publication_venue:first_year }}
    Broken
{{ /if }}

where publication_venue is a linked entry from another collection and first_year is an Integer.

Of course, in my case, "test" !== "test" was a useful bit of code, but I have narrowed it down to this example. I cannot narrow down the second half of the condition with my current knowledge of Statamic.

How to Reproduce

  1. Create a collection A with an Integer fieldtype
  2. Create one entry in that collection with an integer in that fieldtype (a four-digit year if you like)
  3. Create a different collection B with an Entries fieldtype that links to collection A
  4. Create one entry in collection B
  5. Write the above Antlers code in an Antlers html file.
  6. Run the above code

Extra Detail

Here is the error I am getting:

Statamic\View\Antlers\SyntaxError
syntax error, unexpected 'flex' (T_STRING) on line 47 of: <li x-data="{detailsOpen:false}" class="mb-2"> <!-- Publication Header --> <div> <div class="block focus:outline-none focus:bg-gray-50 transition duration-150 ease-in-out"> <div class="px-2"> <div class="flex items-center justify-between"> <div class="text-sm leading-5 font-medium"> {{ title }} </div> <?php if (false): ?> <div class="ml-2 flex-shrink-0 flex"> <span class="inline-flex items-center px-3 py-0.5 rounded-full 

Environment

Statamic 3.0.9 Solo
Laravel 6.18.35
PHP 7.4.9
statamic/ssg dev-master

@LloydThinks LloydThinks changed the title Null Broken Conditional with Statamic Upgrade from 3.0.8 to 3.0.9 Sep 17, 2020
@jasonvarga
Copy link
Member

jasonvarga commented Sep 17, 2020

Thanks for pointing this out.

Are you able to share your actual condition? Obviously "test" == "test" isn't what you're really doing, and comparing two literals doesn't make sense.

If you're doing variable == "string", I noticed that swapping it around to "string" == variable works. You can use that as a workaround for now.

@LloydThinks
Copy link
Author

Hi @jasonvarga yes absoluately:

{{ if publication_venue:publication_venue_types:slug !== "journal" and publication_venue:first_year }}
  Broken
{{ /if }}

Switching the order to:

{{ if "journal" !== publication_venue:publication_venue_types:slug and publication_venue:first_year }}
  Broken
{{ /if }}

did not fix the error. Now I get a new error:

Statamic\View\Antlers\SyntaxError
syntax error, unexpected '{' on line 41 of: <li x-data="{detailsOpen:false}" class="mb-2"> <!-- Publication Header --> <div> <div class="block focus:outline-none focus:bg-gray-50 transition duration-150 ease-in-out"> <div class="px-2"> <div class="flex items-center justify-between"> <div class="text-sm leading-5 font-medium"> {{ title }} </div> <?php if (false): ?> <div class="ml-2 flex-shrink-0 flex"> <span class="inline-flex items-center px-3 py-0.5 rounded-full text-sm font-

Lloyd

@jasonvarga
Copy link
Member

Thank you Lloyd, this is helpful.

@jasonvarga
Copy link
Member

Should be fixed in 3.0.10

@LloydThinks
Copy link
Author

LloydThinks commented Sep 20, 2020

It is not fixed in 3.0.10. Upgrading breaks my site. Deleting this portion of code makes my site work again:

{{ if publication_venue:publication_venue_types:slug !== "journal" and publication_venue:first_year }}
  {{ publication_year subtract="{{publication_venue:first_year}}" add="1" number_suffix="" }}
{{ /if }}

Full Error extends to much higher in the code..

Statamic\View\Antlers\SyntaxError
syntax error, unexpected '{' on line 38 of: <li x-data="{ detailsOpen:false }" class="mb-2"> <!-- Publication Header --> <div> <div class="block focus:outline-none focus:bg-gray-50 transition duration-150 ease-in-out"> <div class="px-2"> <div class="flex items-center justify-between"> <div class="text-sm leading-5 font-medium"> {{ title }} </div> <?php if (false): ?> <div class="ml-2 flex-shrink-0 flex"> <span class="inline-flex items-center px-3 py-0.5 rounded-full text-sm font-medium leading-5 bg-teal-400 text-white"> tag_pair_f5943836f76531775b2664e98baa946d </span> </div> <?php endif; ?> </div> <div class="mt-1 sm:flex sm:justify-between"> <div class="sm:flex"> <div class="mr-6 flex items-center text-sm leading-5 text-gray-500 truncate"> <svg class="flex-shrink-0 mr-1.5 h-4 w-4 text-gray-400" viewBox="0 0 20 20" fill="currentColor"> <path d="M9 6a3 3 0 11-6 0 3 3 0 016 0zM17 6a3 3 0 11-6 0 3 3 0 016 0zM12.93 17c.046-.327.07-.66.07-1a6.97 6.97 0 00-1.5-4.33A5 5 0 0119 16v1h-6.07zM6 11a5 5 0 015 5v1H1v-1a5 5 0 015-5z" /> </svg> tag_pair_c5da79b3b173f61132e255db06974068 </div> </div> </div> <?php if (true): ?> <div class="sm:flex sm:justify-between"> <div class="sm:flex"> <div class="mr-6 flex items-center text-sm leading-5 text-gray-500"> <svg class="flex-shrink-0 mr-1.5 h-4 w-4 text-gray-400" viewBox="0 0 20 20" fill="currentColor"> <path fill-rule="evenodd" d="M4.083 9h1.946c.089-1.546.383-2.97.837-4.118A6.004 6.004 0 004.083 9zM10 2a8 8 0 100 16 8 8 0 000-16zm0 2c-.076 0-.232.032-.465.262-.238.234-.497.623-.737 1.182-.389.907-.673 2.142-.766 3.556h3.936c-.093-1.414-.377-2.649-.766-3.556-.24-.56-.5-.948-.737-1.182C10.232 4.032 10.076 4 10 4zm3.971 5c-.089-1.546-.383-2.97-.837-4.118A6.004 6.004 0 0115.917 9h-1.946zm-2.003 2H8.032c.093 1.414.377 2.649.766 3.556.24.56.5.948.737 1.182.233.23.389.262.465.262.076 0 .232-.032.465-.262.238-.234.498-.623.737-1.182.389-.907.673-2.142.766-3.556zm1.166 4.118c.454-1.147.748-2.572.837-4.118h1.946a6.004 6.004 0 01-2.783 4.118zm-6.268 0C6.412 13.97 6.118 12.546 6.03 11H4.083a6.004 6.004 0 002.783 4.118z" clip-rule="evenodd" /> </svg> tag_pair_1117375c19b79c8a966b77c03590e95c <?php if ('workshop' !== "null): ?> {{ publication_year subtract="{{publication_venue:first_year}}" add="1" number_suffix="" }} <?php endif; ?> {{ publication_venue:title_long }} ({{ publication_venue:title }}) </div> </div> </div> <?php endif; ?> <!-- Container of Small Details --> <div class="flex items-center text-sm leading-5 text-gray-500 sm:mt-0 space-x-2"> <!-- Container of Icons that can hide --> <div class="flex flex-wrap"> <!-- Year Published --> <div class="flex mr-2 items-center"> <svg class="flex-shrink-0 mr-1.5 h-4 w-4 text-gray-400" viewBox="0 0 20 20" fill="currentColor"> <path fill-rule="evenodd" d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z" clip-rule="evenodd" /> </svg> <span> <time datetime="{{ publication_year }}">{{ publication_year }}</time> </span> </div> <!-- Venue Location --> <?php if ('South Korea'): ?> <div class="flex mr-2 items-center"> <svg class="flex-shrink-0 mr-1 h-4 w-4 text-gray-400" viewBox="0 0 20 20" fill="currentColor"> <path fill-rule="evenodd" d="M5.05 4.05a7 7 0 119.9 9.9L10 18.9l-4.95-4.95a7 7 0 010-9.9zM10 11a2 2 0 100-4 2 2 0 000 4z" clip-rule="evenodd" /> </svg> <span>{{ venue_city }}, {{ venue_country }}</span> </div> <?php endif; ?> <!-- Type of Publication --> <?php if (true): ?> <div class="flex mr-2 items-center"> <svg class="flex-shrink-0 mr-1 h-4 w-4 text-gray-400" viewBox="0 0 20 20" fill="currentColor"> <path fill-rule="evenodd" d="M17.707 9.293a1 1 0 010 1.414l-7 7a1 1 0 01-1.414 0l-7-7A.997.997 0 012 10V5a3 3 0 013-3h5c.256 0 .512.098.707.293l7 7zM5 6a1 1 0 100-2 1 1 0 000 2z" clip-rule="evenodd" /> </svg> <span>{{ publication_types:title }}</span> </div> <?php endif; ?> </div> <!-- Dummy Item to push items to the edge --> <div class="flex-auto"></div> <div class="flex space-x-1"> <!-- Open Access Link --> <?php if (NULL): ?> <span class="flex flex-none rounded-md"> <a href="{{ open_access_link }}" class="my-button pub-button"> <svg viewBox="0 0 20 20"> <path fill-rule="evenodd" d="M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4zm2 6a1 1 0 011-1h6a1 1 0 110 2H7a1 1 0 01-1-1zm1 3a1 1 0 100 2h6a1 1 0 100-2H7z" clip-rule="evenodd" /> </svg> PDF </a> </span> <?php endif; ?> <!-- Asset Link --> <?php if (NULL): ?> <span class="flex flex-none rounded-md"> <a href="{{ local_asset:url }}" class="my-button pub-button"> <svg viewBox="0 0 640 1000"> <g stroke-width="104.764"><path d="M111.387 308.135v-35.727a209.21 209.214 0 01418.42 0v258.426"/><circle cx="320.004" cy="680.729" r="256.083"/></g><circle fill="#ffffff" cx="321.01" cy="681.659" r="86.4287"/> </svg> PDF </a> </span> <?php endif; ?> <!-- Publisher Link --> <?php if ('https://doi.org/10.1109/REW.2019.00008'): ?> <span class="flex flex-none rounded-md"> <a href="{{ publisher_link }}" class="my-button pub-button"> <svg viewBox="0 0 20 20"> <path d="M11 3a1 1 0 100 2h2.586l-6.293 6.293a1 1 0 101.414 1.414L15 6.414V9a1 1 0 102 0V4a1 1 0 00-1-1h-5z" /> <path d="M5 5a2 2 0 00-2 2v8a2 2 0 002 2h8a2 2 0 002-2v-3a1 1 0 10-2 0v3H5V7h3a1 1 0 000-2H5z" /> </svg> DOI </a> </span> <?php endif; ?> <!-- Abstract Expand --> <?php if ('Legacy software systems typically include vital data for organizations that use them and should thus to be regularly maintained. Ideally, organizations should rely on Requirements Engineers to understand and manage changes of stakeholder needs and system constraints. However, due to time and cost pressure, and with a heavy focus on implementation, organizations often choose to forgo Requirements Engineers and rather focus on ad-hoc bug fixing and maintenance. This position paper discusses what Requirements Engineers could possibly learn from other similar roles to become crucial for the evolution of legacy systems. Particularly, we compare the roles of Requirements Engineers (according to IREB), Building Architects (according to the German regulations), and Product Owners (according to "The Scrum-Guide"). We discuss overlaps along four dimensions: liability, self-portrayal, core activities, and artifacts. Finally we draw insights from these related fields to foster the concept of a Requirements Engineer as a distinguished profession.'): ?> <span @click="detailsOpen = !detailsOpen" class="flex flex-none rounded-md"> <a class="my-button pub-button"> <svg viewBox="0 0 20 20"> <path fill-rule="evenodd" d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 15a1 1 0 011-1h6a1 1 0 110 2H4a1 1 0 01-1-1z" clip-rule="evenodd" /> </svg> Abs </a> </span> <?php endif; ?> </div> </div> </div> </div> </div> <div x-show="detailsOpen" x-cloak> <div class="block focus:outline-none focus:bg-gray-50 transition duration-150 ease-in-out"> <div class="px-4 py-4 sm:px-6 text-sm text-justify text-gray-500"> {{ abstract }} </div> </div> </div> <!-- <?php if (!false): ?> <div class="border-t border-gray-200"></div><?php endif; ?> --> </li>

Let me know if you want my full site to be sent to you personally, if it helps debug this parsing issue.

Lloyd

@LloydThinks
Copy link
Author

LloydThinks commented Oct 8, 2020

For those that may run into this issue, I have resolved the issue by separating out the individual conditions into two separate nested {{ if }} statements. I still believe my original conceptualisation is okay, but not able to be parsed.

{{ if publication_venue:publication_venue_types:slug !== "journal" }}
{{ if publication_venue:first_year }}
  {{ publication_year subtract="{{publication_venue:first_year}}" add="1" number_suffix="" }}
{{ /if }}
{{ /if }}

@duncanmcclean
Copy link
Member

Related to either #2614 or #2537.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants