Modx Get page and sorting with &sortbyTV - modx

Ok, before anyone points me to the Modx RTFM, let me just say, that I've actually implemented this on a few sites, using getpage rather than just getresources and they have all worked according to my needs, and what those needs were was to give visitors the ability to sort a list according to a template variable.
Now in all instances I used a listbox (single select)template variable as so (in this case for rating):
1==[[$one_star]] || 1.5==[[$one_and_half]] || 2==[[$two_star]] || 2.5==[[$two_and_half]] || 3==[[$three_star]] || 3.5==[[$three_and_half]] || 4==[[$four_star]] || 4.5==[[$four_and_half]] || 5==[[$five_star]]
Now, on my current project which is days from launch, I created a template variable called "price", in which the numerical value is entered into a text field, nothing more and, for some reason, getpage doesn't return the proper output. For example on a "low to high" page the first in the list is not the lowest priced item.
here's an example of the call. (I use getpage for pagination)
[[!getPage?
&elementClass=`modSnippet`
&showHidden=`1`
&sortbyTV=`price`
&sortdirTV=`ASC`
&element=`getResources`
&parents=`7,8,9,10,11,12`
&limit=`8`
&pageLimit=`2`
&pageVarKey=`page`
&includeTVs=`1`
&includeContent=`1`
&tpl=`store_post`
&tvPrefix=`tv.`
&cache=`0`
]]
<div class="paging">
<ul class="pageList">
[[!+page.nav]]
</ul>
</div>
and here's the template:
<div class="product_info_container">
<div class="product_name">[[+tv.product_name]]</div>
<div class="product_details">[[+tv.product_details]]</div>
<div class="product_price">price: [[+tv.price]] USD</div>
<div class="product_purchase">[[+tv.pay_button]]</div>
<div class="view_cart">[[$viewcart]]</div>
</div>
I'm on Revolution 2.2.13-pl (I tried updating to 2.2.14 but there was a php error which scared the heck outta me and until I isolate the cause, with launch looming, I'm not touching it! :P) All packages are current as well.
Any help or suggestions would be greatly appreciated because, needless to say, I'm stumped :)
p.s. I know the above getpage call is for ASC not DESC...I was just using the low to high as an example

Related

How to fix the error of Maximum call stack size exceeded when using pattern lab?

In pattern lab Maximum call stack size exceeded error and I don't know why. I'm not doing anything that I haven't done before.
In 01-molecules/02-cart/cart.mustache I have this code
{{#miniCart}}
<div class="mini_cart_item">
<img class="mini_cart_image" src={{img}} alt="">
<div class="mini_cart_info">
<span>£{{price}}</span>
<h4 class="mini_cart_title">{{title}}</h4>
</div>
</div>
{{/miniCart}}
That data comes from 01-molecules/02-cart/cart.json. It works fine.
Then I have 02-organisms/mini-cart.mustache and the code is
<div class="mini_cart">
{{#miniCart}}
{{> cart}}
{{/miniCart}}
</div>
The cart comes from the molecule above, the data comes from 02-organisms/mini-cart.json. Is is the some json code just with more objects.
That {{> cart}} throws the Maximum call stack size exceeded error. If I remove that line of code and replace it with anything, like {{title}} the code just works.
What might be the problem?
To run pattern lab I am running this
/MyMAMP/www/2016/edition-node-gulp/node_modules/gulp/bin/gulp.js patternlab:serve
From google search I tried this
/MyMAMP/www/2016/edition-node-gulp/node_modules/gulp/bin/gulp.js patternlab:serve --stack_size=2048
but the result is the same thing.
Maintainer of Pattern Lab Node here.
{{> cart}} should be {{> molecules-cart}}
Give that a shot.
remove reference to 'miniCart' template inside the 'cart' template
this causes an infinite recursion in template engine

flask_moment current time refresh in browser not updating

Following basic setup with python3.4, jinja2, flask_moment (0.5.1), Flask(0.10.1) integration.
I am trying out the capability to simply understand the workings.
The example is nonsensical but I want to get browser to display:
firstly, the actual time in real time ("The local time is ...") continually updated in real time
secondly, the time elapsed ("That was ...").
Jinja2 code:
<p>The local time is {{ moment(current_time).format('LT', refresh=True) }}.</p>
<p>That was {{ moment(current_time).fromNow(refresh=True) }}</p>
The second line refresh works fine in the browser ("That was 1/2/3 minutes ago"), indicating all libraries working correctly, but the first line refresh doesn't work.
The method moment(current_time).format('LT', refresh=True) I thought would display the time in real time with the refresh option set to "True", but it doesn't.
Looking at browser markup, all the libraries are there and there are no errors. See markup below.
Any hints appreciated or maybe I am misunderstanding the capability?
Browser source:
<div class="container">
<div class="page-header">
<h1>Hello, Flask!</h1>
</div>
</div>
<p>The local time is <span class="flask-moment" data-timestamp="2016-01-28T12:19:20Z" data-format="format('LT')" data-refresh="60000" style="display: none">2016-01-28T12:19:20Z</span>.</p>
<p>That was <span class="flask-moment" data-timestamp="2016-01-28T12:19:20Z" data-format="fromNow(0)" data-refresh="60000" style="display: none">2016-01-28T12:19:20Z</span></p>
<script src="/static/bootstrap/jquery.min.js?bootstrap=3.3.5.7"></script>
<script src="/static/bootstrap js/bootstrap.min.js?bootstrap=3.3.5.7"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment-with-locales.min.js"></script>
<script>
moment.locale("en");
function flask_moment_render(elem) {
$(elem).text(eval('moment("' + $(elem).data('timestamp') + '").' + $(elem).data('format') + ';'));
$(elem).removeClass('flask-moment').show();
}
function flask_moment_render_all() {
$('.flask-moment').each(function() {
flask_moment_render(this);
if ($(this).data('refresh')) {
(function(elem, interval) { setInterval(function() { flask_moment_render(elem) }, interval); })(this, $(this).data('refresh'));
}
})
}
$(document).ready(function() {
flask_moment_render_all();
});
This is a misunderstanding on how Flask-Moment works, probably due to my not very clear documentation.
The moment(current_time).format('LT', refresh=True) expression that you put in the Jinja template runs in the server, not the browser. In particular, the current_time variable has a fixed value that I presume you assigned in the Python code.
The result of running this expression is some Javascript code that runs on the browser. When you pass refresh=True, this Javascript code runs every minute. But while the code does run repeatedly, the rendered time is always the same, because a value for current_time was set on the server and isn't being updated. The use of auto-refresh only makes sense with one of the "dynamic" rendering options of moment.js, such as the "X secs/mins ago" format, because those change as time passes.
If you wanted to implement something like a clock, that updates the time, then you would probably need a solution that does it all in Javascript on the browser.
So it appears that according to the documentation, the refresh=true is only going to be updated every minute. Have you given it a minute to verify that it's not refreshing?
The rendered dates and times can be refreshed periodically by passing
a refresh = True argument to any of the above functions. This is
useful for the relative formats, because they are updated as time
passes. The refresh interval is fixed at one minute.
http://blog.miguelgrinberg.com/post/flask-moment-flask-and-jinja2-integration-with-momentjs

DustJS logic to verify empty string

I need to write logic to check whether the value is empty or it has string. Any help on this.. i tried this following. but it doesn't work in nodejs and throwing error
{#if cond="'{notes}' != '' || '{errors}' != '' "}
display html
{/if}
The #if helper is deprecated and should not be used. However, based on the code you've given, you should probably be able to use an exists check.
{?notes}
{?errors}
{! Display HTML !}
{/errors}
{/notes}
If that doesn't work for some reason, you could use the #ne helper.
{#ne key=notes value=""}
...
{/ne}
If that still isn't good enough, you could try writing a context helper. The documentation on dustjs.com is excellent.
{?notes}
Display HTML
{:else}
{?errors}
Display HTML
{/errors}
{/notes}
should do the trick.

jstree - searching for a node returns the complete jstree

I use the following code to search for a specific node text:
$("#create_1").click(function () {
node = $("#patterneditor").jstree("search", "report");
node.css("font-weight", "bold");
});
Here is the part from the html-data tree:
<li rel="hashkey" class="jstree-open">
report
<ul>
<li rel="hash" class="jstree-open">Hash
<ul>
But when executing the search and applying the css-settings all tree nodes become bold.
The "report"-node becomes italic (so i think the search worked below a given point), but I want to have the node object stored in the node variable.
Does anyone know why this happens and how this can get fixed?
Regards
Tristan
It turned out, that the search-functionality is not able to get the object of the node I've searched. Instead i used something like
node = $("#patterneditor").jstree("select_node", $("[pattern_section='pattern']"));
$("#patterneditor").jstree("create", node);
holy cow ..

Problem listing documents in a CouchApp

I am in a bit of trouble as I am not able to find resources and/or tutorials that give me enough knowledge how to do this properly:
I am building a Couchapp uppon a contact database. For this I need to have a unordered list of the contacts(only the names) on the landing page. After examining this now for quite a time and examining the http://kansojs.org framework, I think I might have to ask here at Stackoverflow how this is done properly...
Here is what I ended up with (not working):
I started to setup a view (file 'views/contactslist/map.js ):
function(doc) {
if (doc.displayName) {
emit(doc.displayName, {displayname: doc.displayName});
}
};
... which basically gives me back this response:
{"total_rows":606,"offset":0,"rows":[
{{"id":"478d86edbbd94bbe627f3ebda309db7c","key":"Al Yankovic","value":{"displayname":"Al Yankovic"}},
{"id":"478d86edbbd94bbe627f3ebda30bb5cb","key":"Al-Qaeda","value":{"displayname":"Al-Qaeda"}}
]}
Afterwards, I created a new directory in the evently directory, 'contacts' and created the files "mustache.html", "data.js" and "query.json":
mustache.html:
<ul>
{{#contacts}}
<li>
<div class="name">
{{displayname}}
</div>
<div style="clear:left;"></div>
</li>
{{/contacts}}
</ul>
data.js:
function(data) {
$.log(data)
var p;
return {contacts : data.rows};
};
query.json:
{
"view" : "contactslist",
"descending" : "true"
}
Then I added
and
$("#contacts").evently("contacts", app);
to the index.html in the _attachments directory.
Watching the console in Firebug I can not see any Request/Response from CouchDB returning my vie's results, so I think it is not even requested. Where did I take the wrong turn?
data.js, query.json and mustache.html need to be in evently/contacts/_init/
_init means that this gets executed on widget initialization.
Going over this Tutorial helped a lot.

Resources