Skip to content

Instantly share code, notes, and snippets.

@cole007 cole007/revealSecret.twig Secret
Created Dec 4, 2018

Embed
What would you like to do?
{% macro revealSecret(startId, elements) %}
{% set outputInt = startId %}
{% set outputStr = startId %}
{% set end = false %}
{% for i in 0..elements|length if end == false %}
{% set el = elements[outputInt] %}
{% if '+' in el.nextElement %}
{% set arr = el.nextElement|split('+') %}
{% set output = arr[0] + arr[1] %}
{% elseif '*' in el.nextElement %}
{% set arr = el.nextElement|split('*') %}
{% set output = arr[0] * arr[1] %}
{% elseif '/' in el.nextElement %}
{% set arr = el.nextElement|split('/') %}
{% set output = arr[0] / arr[1] %}
{% elseif '-' in el.nextElement %}
{% set arr = el.nextElement|split('-') %}
{% set output = arr[0] - arr[1] %}
{% else %}
{% set output = el.nextElement %}
{% endif %}
{% if el.nextElement is null %}
{% set end = true %}
{% set outputStr = outputStr ~ ' > ' ~ el.title %}
{% else %}
{% set outputInt = output %}
{% set outputStr = outputStr ~ ' > ' ~ output %}
{% endif %}
{% endfor %}
{{ outputStr }}
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.