I have finally (I think) managed to implement a second language using the multi language alternative wiki in ExpressionEngine.
The problem I’m having is that when i try and add the following if statement (or others)
{if country_code == “fr”} {/if}
around my otherwise fine navee navigation tag, the whole page becomes destroyed.
Upon viewing source, adding the if statement removes LOTS of code before and after it.
It is removing closing tags from before and after the statement, effectively sending the page all over the place.
Does anyone know why this may be the case?
EDIT: Here is the full code:
<div id="top_links">
<ul id="top_links_list">
<li>t: +33 (0)467 45 90 00</li>
<li>e: <a href="mailto:#>Email</a></li>
{if segment_1 == "hotel" OR segment_1 == "contact"}
<li class="hotel_reserve">
{if country_code == "fr"}Réservez votre séjour{/if}{if country_code == "en"}Reserve your stay{/if}
</li>
{/if}
{if segment_1 == "restaurants" AND segment_2 !="reservations" AND segment_2 !="merci"}
<li class="restaurants_reserve">
{if country_code == "fr"}Réservez votre table{/if}{if country_code == "en"}Reserve your table{/if}
</li>
{/if}
{if segment_1 == "golf" AND segment_2 !="reservations" AND segment_2 !="merci"}
<li class="golf_reserve">
{if country_code == "fr"}Réservez votre départ{/if}{if country_code == "en"}Reserve your tee-time{/if}
</li>
{/if}
{if segment_1 == "evenements" AND segment_2 !="reservations" AND segment_2 !="merci"}
<li class="evenements_reserve">
{if country_code == "fr"}Demandez un devis{/if}{if country_code == "en"}Get a quote{/if}
</li>
{/if}
{if segment_1 == "competitions" AND segment_2 == "view"}
<li class="competitions_retour">
{if country_code == "fr"}Retour au page compétitions{/if}{if country_code == "en"}Return to competitions page{/if}
</li>
{/if}
{if segment_1 == "competitions" AND segment_2 == "merci"}
<li class="competitions_retour">
Retour au page {segment_1}
</li>
{/if}
{if segment_1 == "golf" AND segment_2 == "merci"}
<li class="competitions_retour">
Retour au page {segment_1}
</li>
{/if}
{if segment_1 == "restaurants" AND segment_2 == "merci"}
<li class="restaurants_reserve">
Retour au page {segment_1}
</li>
{/if}
{if segment_1 == "evenements" AND segment_2 == "merci"}
<li class="evenements_reserve">
Retour au page {segment_1}
</li>
{/if}
{if segment_1 == "merci"}
<li class="evenements_reserve">
Retour au page contact
</li>
{/if}
{if segment_1 == "events" AND segment_2 == "view"}
<li class="evenements_reserve">
Retour au page Events
</li>
{/if}
</ul>
</div> <!-- end top links -->
{if country_code == "fr"}
{exp:navee:nav nav_title="main_nav" id="nav" parent_selected_class="parent_selected" selected_class_on_parents="true"}
{/if}
</div> <!-- end top right area -->
<div class="clear"></div>
</div> <!-- END TOP AREA -->
Thanks.
In your case, I would use probably Switchee which is far better then tons of if conditional.
Your source code seems to have fancy quotes:
{if country_code == “fr”} {/if}
{if country_code == "fr"} {/if}
See the difference? Try the second line.
You need to make sure you adhere to the directory listing rules and have created all directories and matching folders and rules, referenced.
Change your code to this:
<h2 class="title">{if country_code= "fr"} Bonjour !{/if}</h2>
Note the quote marks are "" and not “” and no double ==
Related
<div class="widget-header" style="margin-top: 5%;">
<ul class="nav nav-tabs">
<li class="<c:if test="${tab != 'LETTERS'}">selected active </c:if>inline headerDivider">
<a class="<c:if test="${tab != 'LETTERS'}">active </c:if>header" href="action" data-toggle="tab"><Regulations</a>
</li>
<li class="<c:if test="${tab == 'LETTERS'}">selected active </c:if>inline headerDivider">
<a class="<c:if test="${tab == 'LETTERS'}">>selected active </c:if>header" href="action" data-toggle="tab">Letters</a>
</li>
<c:choose>
<c:when test="${tab != 'LETTERS'}">
<a data-href="action" class="btn btn-small" data-toggle="modal" data-reload="regulationDiv">Manage Regulations</a>
</c:when>
<c:otherwise>
<a data-href="action" class="btn btn-small" data-toggle="modal" data-reload="letterDiv">Add Letter</a>
</c:otherwise>
</c:choose>
</ul>
</div>
<div style="overflow: auto; max-height:60vh;" class="tab-content">
<c:if test="${tab != 'LETTERS'}">
<div id="regulationDiv" data-url='action'>
<jsp:include page="regulations.jsp"/>
</div>
</c:if>
<c:if test="${tab == 'LETTERS'}">
<div id="letterDiv" data-url='action'>
<jsp:include page="letters.jsp"/>
</div>
</c:if>
</div>
First tab by default its working second tab there is no event or click, looks like disabled tab.Am I missing something to include in div elements, I tried many ways seems no solution yet to me.
I would like to remove withe spaces or new lines from a string that comes from a html sentence.
Example: lets take the follow string
<ul class="list-group sidebar-nav-v1 margin-bottom-40" id="menuHomeUserPrivate">
<li class="list-group-item active">
<a id="to_ProfileOverall" class="privateMenuLinkJS"><i class="fa fa-bar-chart-o"></i> Overall</a>
</li>
<li class="list-group-item list-toggle">
<a data-toggle="collapse" data-parent="#menuHomeUserPrivate" href="#collapse-MoneyManage" ><i class="fa fa-money"></i> Invoice</a>
<ul id="collapse-MoneyManage" class="collapse">
<li><a id="to_MoneyManagerFaturamentoInsert" class="privateMenuLinkJS"><i class="fa fa-level-down"></i> Big Invoice </a></li>
<li><a id="to_MoneyManagerFaturamentoGerir" class="privateMenuLinkJS"><i class="fa fa-cogs"></i> Big big big
Invoice 2 </a></li>
</ul>
</li>
</ul>
This is the desired result:
<ul class="list-group sidebar-nav-v1 margin-bottom-40" id="menuHomeUserPrivate"><li class="list-group-item active"><a id="to_ProfileOverall" class="privateMenuLinkJS"><i class="fa fa-bar-chart-o"></i>Overall</a></li><li class="list-group-item list-toggle"><a data-toggle="collapse" data-parent="#menuHomeUserPrivate" href="#collapse-MoneyManage" ><i class="fa fa-money"></i> Invoice</a><ul id="collapse-MoneyManage" class="collapse"><li><a id="to_MoneyManagerFaturamentoInsert" class="privateMenuLinkJS"><i class="fa fa-level-down"></i>Big Invoice</a></li><li><a id="to_MoneyManagerFaturamentoGerir" class="privateMenuLinkJS"><i class="fa fa-cogs"></i>Big big big Invoice 2</a></li></ul></li></ul>
As you can see:
Only 1 line, no withe spaces or new lines between "><" if there is no string between them.
I would like to have trimmed strings between "><" if there are some. Example: </i> Big Invoice </a> became </i>Big Invoice</a>.
And finally
</i> Big big big
Invoice 2 </a></li>
became </i>Big big big Invoice 2</a></li>, no new line in the middle of the sentence and trimmed.
So far I achieved the first step. This is the regex I used (>\s+<) but I don't know how to achieve the step 2 and 3. Is it possible? Any idea?
Update:
After Adam's post, this the final code:
//Put your html code here. Do not use double quotes " inside it. Instead, use single.
$str =<<<eof
your dynamic HTML here.
eof;
$re = "/(?:\\s*([<>])\\s*|(\\s)\\s*)/im";
$subst = "$1$2";
$result = preg_replace($re, $subst, $str);
//If you want to use JSON
$arrToJSON = array(
"dataPHPtoJs"=>"yourData",
"htmlDyn"=>"$result"
);
$resultJSON= json_encode(array($arrToJSON));
This html string is clean. So you can use it trough AJAX, JSON, inside javascript, that will works.
I my case I am using inside a javascript code, no AJAX, no JSON.
var htmlDyn="<?php echo $result; ?>";
//Do what you want to do with.
$('.someElementClass').append(htmlDyn);
Here is the solution:
(?:\s*([<>])\s*|(\s)\s*)
Substitution:
\1\2
You can try it here:
https://regex101.com/r/dL5gB5/1
Some XML conversions if you please?
The following snippet is in PHP but could easily transformed to work with i.e. Python as well.
<?php
$string = <<<EOF
<html>
<ul class="list-group sidebar-nav-v1 margin-bottom-40" id="menuHomeUserPrivate">
<li class="list-group-item active">
<a id="to_ProfileOverall" class="privateMenuLinkJS"><i class="fa fa-bar-chart-o"></i> Overall</a>
</li>
<li class="list-group-item list-toggle">
<a data-toggle="collapse" data-parent="#menuHomeUserPrivate" href="#collapse-MoneyManage" ><i class="fa fa-money"></i> Invoice</a>
<ul id="collapse-MoneyManage" class="collapse">
<li><a id="to_MoneyManagerFaturamentoInsert" class="privateMenuLinkJS"><i class="fa fa-level-down"></i> Big Invoice </a></li>
<li><a id="to_MoneyManagerFaturamentoGerir" class="privateMenuLinkJS"><i class="fa fa-cogs"></i> Big big big
Invoice 2 </a></li>
</ul>
</li>
</ul>
</html>
EOF;
$xml = simplexml_load_string($string);
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = false;
$dom->loadXML($xml->asXML());
echo $dom->saveXML();
/* output:
<html><ul class="list-group sidebar-nav-v1 margin-bottom-40" id="menuHomeUserPrivate"><li class="list-group-item active"><a id="to_ProfileOverall" class="privateMenuLinkJS"><i class="fa fa-bar-chart-o"/> Overall</a></li><li class="list-group-item list-toggle"><a data-toggle="collapse" data-parent="#menuHomeUserPrivate" href="#collapse-MoneyManage"><i class="fa fa-money"/> Invoice</a><ul id="collapse-MoneyManage" class="collapse"><li><a id="to_MoneyManagerFaturamentoInsert" class="privateMenuLinkJS"><i class="fa fa-level-down"/> Big Invoice </a></li><li><a id="to_MoneyManagerFaturamentoGerir" class="privateMenuLinkJS"><i class="fa fa-cogs"/> Big big big
Invoice 2 </a></li></ul></li></ul></html>
*/
?>
Eliminates all unnecessary whitespace and is safer then using regular expressions on HTML tags.
This will trim the whitespaces adjacent to tags and remove newlines in the middle of content.
Find:
(?:\s*(<(?:(?:/?[\w:]+\s*/?)|(?:[\w:]+\s+(?:(?:(?:"[\S\s]*?")|(?:'[\S\s]*?'))|(?:[^>]*?))+\s*/?)|\?[\S\s]*?\?|(?:!(?:(?:DOCTYPE[\S\s]*?)|(?:\[CDATA\[[\S\s]*?\]\])|(?:--[\S\s]*?--)|(?:ATTLIST[\S\s]*?)|(?:ENTITY[\S\s]*?)|(?:ELEMENT[\S\s]*?))))>)\s*|(?:\r?\n)+)
Replace:
$1
Output:
<ul class="list-group sidebar-nav-v1 margin-bottom-40" id="menuHomeUserPrivate"><li class="list-group-item active"><a id="to_ProfileOverall" class="privateMenuLinkJS"><i class="fa fa-bar-chart-o"></i>Overall</a></li><li class="list-group-item list-toggle"><a data-toggle="collapse" data-parent="#menuHomeUserPrivate" href="#collapse-MoneyManage" ><i class="fa fa-money"></i>Invoice</a><ul id="collapse-MoneyManage" class="collapse"><li><a id="to_MoneyManagerFaturamentoInsert" class="privateMenuLinkJS"><i class="fa fa-level-down"></i>Big Invoice</a></li><li><a id="to_MoneyManagerFaturamentoGerir" class="privateMenuLinkJS"><i class="fa fa-cogs"></i>Big big big Invoice 2</a></li></ul></li></ul>
Benchmark:
Regex1: (?:\s*(<(?:(?:/?[\w:]+\s*/?)|(?:[\w:]+\s+(?:(?:(?:"[\S\s]*?")|(?:'[\S\s]*?'))|(?:[^>]*?))+\s*/?)|\?[\S\s]*?\?|(?:!(?:(?:DOCTYPE[\S\s]*?)|(?:\[CDATA\[[\S\s]*?\]\])|(?:--[\S\s]*?--)|(?:ATTLIST[\S\s]*?)|(?:ENTITY[\S\s]*?)|(?:ELEMENT[\S\s]*?))))>)\s*|(?:\r?\n)+)
Options: < none >
Completed iterations: 50 / 50 ( x 1000 )
Matches found per iteration: 29
Elapsed Time: 6.75 s, 6749.58 ms, 6749576 µs
I'm checking the routes inside my blade template, to add an active class to a specific li in my menu with this code:
<ul>
<li class="{{ Request::is('*/sobre') || Request::is('*') ? "active" : "" }}">
Sobre o salão
</li>
<li class="{{ Request::is('*/servicos') ? "active" : "" }}">
Serviços
</li>
<li class="{{ Request::is('*/avaliacoes') ? "active" : "" }}">
Avaliações
</li>
<li class="{{ Request::is('*/galeria') ? "active" : "" }}">
Fotos
</li>
</ul>
And those are the routes:
Route::group(['prefix' => '{domain}', 'middleware'=>'salao'], function () {
Route::get('/', 'Frontend\FrontendSalaoController#sobre');
Route::get('sobre', 'Frontend\FrontendSalaoController#sobre');
Route::get('servicos', 'Frontend\FrontendSalaoController#servicos');
Route::get('avaliacoes', 'Frontend\FrontendSalaoController#avaliacoes');
Route::get('galeria', 'Frontend\FrontendSalaoController#galeria');
});
When i access the route http://website/x or the route http://website/x/sobre, the active class is positioned correctly. But, if I access the http://website/x/servicos route, the class will be added in the first li and in the servicos li.
How can i handle this?
Request::is('*') actually matches everything so the first item will always have the active class. Instead you should check for '/':
<li class="{{ Request::is('*/sobre') || Request::is('/') ? "active" : "" }}">
The is method even supports multiple parameters, of which only one has to match, so you can shorten it to this:
<li class="{{ Request::is('*/sobre', '/') ? "active" : "" }}">
I'm trying to set multiple css classes on one element.
Unfortunately this doesn't work, as it returns: LanguageError: Duplicate attribute name in attributes.
<ul>
<li tal:repeat="item mainnav"
tal:attributes="class 'first' if repeat.item.start else nothing;
class 'last' if repeat.item.end else nothing;
class 'active' if item.active else nothing">
<a tal:attributes="href item.href" tal:content="item.title">title</a>
</li>
</ul>
Combining those 3 cases into one expression makes it quite complicated, because there are 6 different css states:
first + active
first
last + active
last
active
(none)
There are 2 possible solutions that I can think of:
-> check each combination inline:
<ul>
<li tal:repeat="item mainnav"
tal:attributes="
class 'first active' if (repeat.item.start and item.active) else
'first' if repeat.item.start else
'last active' if (repeat.item.end and item.active) else
'last' if repeat.item.end else
'active' if item.active else nothing">
<a tal:attributes="href item.href" tal:content="item.title">title</a>
</li>
</ul>
-> create a method that returns the combined css classes
Now, is there a better approach and if not, which of those 2 is better (probably the latter one, as if it gets more complicating the inline script will become unreadable/unmanageable).
BTW, are there any good resources and examples about Chameleon, TALES (other than http://chameleon.repoze.org/docs/latest)
You can use tal:define multiple times to define the various parts of your class string, then construct the actual attribute from those parts:
<tal:loop repeat="item mainnav">
<li tal:define="class_first 'first' if repeat.item.start else '';
class_last 'last' if repeat.item.end else '';
class_active 'active' if item.active else '';"
tal:attributes="class string:$class_first $class_last $class_active">
<a tal:attributes="href item.href" tal:content="item.title">title</a>
</li>
</tal>
This could result in an empty class attribute, which is harmless.
As for additional documentation; Chameleon is an implementation of TAL, originally developed for Zope Page Templates. As such, you'll find a lot of documentation for the latter also applies to Chameleon, as long as you take into account that Chameleon's default TALES modus is python:, while ZPT defaults to path: instead. The Advanced Page Templates chapter of the Zope Book applies to Chameleon as well, for example.
In Chameleon you can do:
<ul>
<li tal:repeat="item mainnav"
class="${'first' if repeat.item.start else ''}
${'last' if repeat.item.end else ''}
${'active' if item.active else ''">
<a tal:attributes="href item.href" tal:content="item.title">title</a>
</li>
</ul>
[Edit]
Or better like this:
<ul>
<li tal:repeat="item mainnav"
class="${('first ' if repeat.item.start else '') +
('last ' if repeat.item.end else '') +
('active' if item.active else '')}">
<a tal:attributes="href item.href" tal:content="item.title">title</a>
</li>
</ul>
You're not using tal:condition, it has a purpose. I don't like overly nested conditionals, gets you no where.
Haven't tested this but you may get the idea.
<ul>
<tal:myloop tal:repeat="item mainnav">
<li tal:condition="item.active" tal:attributes="class
'active first' if repeat.item.start
else 'active last' if repeat.item.end
else 'active'">
<a tal:attribute="href item.href" tal:content="item.title"></a>
</li>
<li tal:condition="not item.active" tal:attributes="class
'first' if repeat.item.start
else 'last' if repeat.item.end else None">
<a tal:attribute="href item.href" tal:content="item.title"></a>
</li>
</tal:myloop>
</ul>
I'm a EE newbie.
I have the code below. the poll weblog displays at search result page, but doesn't display at blog and post details page :/ what am I missing?
display at search result page: www.blabla.com/search/noresults/d8ee432f229715a4adfbe1cc0d21049a/
NO display at blog pages: www.blabla.com/blog/ or www.blabla.com/blog/post/lorem_ipsum_is_simply_dummy_text/
Appreciate helps!!!! Thanks a lot!
{exp:weblog:entries weblog="lg_polls"}
{exp:lg_polls:poll entry_id="29" precision="1" return="/blog/"}
<p>{poll_question}</p>
{if can_vote}
{poll_form}
{if has_voted}<p>You have already voted in this poll, however you can vote again.</p>{/if}
<ul class='lg-polls-answers'>
{poll_answers}
<li class='a-{answer_count}'>
<label for='lg-polls-answer-{answer_id}'>{answer_input} <span class='answer'>{answer}</span></label>
</li>
{/poll_answers}
</ul>
<div class="alignCenter"><input type="image" src="{site_url}/images/btn_submitpoll.png" alt="Vote" /></div>
{/poll_form}
{if:else}
{if has_voted}<p>Thanks for voting in this poll.</p>{/if}
{if restricted}<p>Sorry, You are restricted from voting in this poll.</p>{/if}
{if expired}<p>This poll ended on {expiration_date}.</p>{/if}
{if yet_to_begin}<p>This poll is yet to begin. Voting opens on {entry_date}.</p>{/if}
{/if}
{if show_results}
<div class='lg-poll-results' id='lg-poll-results-29'>
<ul class='lg-polls-answers'>
{results_answers}
<li class='a-{answer_count}'>
<span class='answer'>{answer}</span>
<span class='answer-total-votes'>{answer_total_votes} votes <b>{answer_percentage}%</b></span>
</li>
{/results_answers}
</ul>
<div class='poll-total-votes'>Total Votes: {poll_total_votes}</div>
</div>
{if:else}
{if show_results_after_poll && has_voted}The results of the poll will be made available on {expiration_date}{/if}
{if never_show_results && has_voted}The results of this poll will be made public at a later date.{/if}
{/if}
{/exp:lg_polls:poll}
{/exp:weblog:entries}
I'm not 100% sure, since I haven't used LG Polls before, but try adding in dynamic="off" to your exp:weblog:entries opening tag. That will prevent EE from trying to find entries within the weblog you're calling based on the URL. See the link below:
http://expressionengine.com/legacy_docs/modules/weblog/parameters.html#par_dynamic