Is it possible to use multiple tpl's in the getResources call?
This is my code so far:
[[!getPage?
&element=`getResources`
&tpl=`overzichtTpl`
&parents=`2, 74`
&hideContainers=`0`
&showHidden=`1`
&limit=`50`
&sortby=`RAND()`
&depth=`0`
&includeTVs=`1`
]]
What I want to achieve is the folowing: the resource call
&parent=`2`
has to use
&tpl=`overzichtTpl`
and the
&parent=`74`
has to use
&tpl=`overzichtAdvTpl`
Furthermore I want to have the output from both calls displayed at random. (otherwise I only have to use 2 seperate getResources calls). For example like this:
resource-call
If you have the solution, I'm looking forward to hear from you.
This is clearly documented using tpl_N & tplnN:
https://rtfm.modx.com/extras/revo/getresources
If you need to randomize your templates, write a snippet and execute it from the getResources call (i.e. &tpl=`RandomizeChunkName`) You don't need an extra wrapper chunk.
Related
I have the following getResources code on a page:
[[!getResources?
&resources=`57,77`
&depth=`1`
&tpl=`customersListTPL`
&limit=`99`
&sortdir=`ASC`
&includeTVs=`1`
&processTVs=`1`
&includeContent=`1`
&showHidden=`1`
&depth=`0`
&sortby=`menuindex`
]]
I want it to only display data from the resources 57 and 77, but it is also displaying child resources from the resource this is on too.
Anyway I can stop that?
For some design-reason getResources will allways mix results from the defined parents (explicit or implicit) if the &parents config is not set.
If you only want to use the defined &resources you have to explicitly disable the parents by using:
&parents=`-1`
For reference: That's not the only oddity of getResources, the limit is preset to 5 and the sort order is createdon=DESC (for example).
Manual: https://rtfm.modx.com/extras/revo/getresources#getResources-Examples
I need my [[+idx]] tv to start at 0 instead of 1 so I tried this:
[[+idx:decr]] or [[+idx:substract=1]] but it gives me -1 (minus one).
Does anyone know another way to obtain 0?
Thank you
Using this in chunk for getImageList works (at least for me):
[[+idx:decr]]
It gives: 0,1,2,3 ....
P.S. using modx revo 2.3.1
set your template variable default to 0 when you create the variable.
What are you trying to do, your question is vague at best.
UPDATE
ok - what I think will work for you is to write a snippet to do the math... where ever you call the [[+idx]] instead write a snippet
[[!FixIDX? &itemindex=`[[+idx]]`]]
then in your FixIDX snippet just do the math with php and return the corrected index. Though perhaps a custom output modifier would be the better way to go: http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters+(Output+Modifiers)
Though looking at the docs, your code should certainly work - I see no reason for it not to.
In MODx Revolution, while using getResources and a custom date TV (called: press-release-date), how can I limit my results by year (using a URL param to set the year, so I could enter any year)?
For example, my URL has page.html?year=2012
I want my results from getResources to only include ones associated with that year. I believe I want to use the &where property (if so, I am certainly botching the formatting):
&where=`{"press-release-date":[[*press-release-date:strtotime:date=`%Y`]:isequalto:`2012`]}`
I've also tried
&where=`{[[*press-release-date]]:[[*press-release-date:strtotime:date=`%Y`]:isequalto:`2012`]}`
Thanks!
UPDATE:
This is the full code I am using currently:
[[!getResources?
&parents=`780,781,782,783,784`
&tpl=`list-press-tpl`
&limit=`1000`
&sortdir=`DESC`
&includeTVs=`1`
&includeContent=`1`
&depth=`0`
&showHidden=`1`
&sortbyTV=`press-release-date`
&where=`{[[*press-release-date]]:[[*press-release-date:strtotime:date=`%Y`]:isequalto:`2012`]}`
]]
You are going to want to use the &tvFilters attribute: http://rtfm.modx.com/display/ADDON/getResources you will probably have to also &includeTVs, &includeTvsList and ~possibly~ also &processTVList. As to how to strip the post value from the url, you may have to write a quick little snippet that grabs all your url variables & sets them as placeholders. something along the lines of:
foreach($_POST as $key => $value){
$modx->setPlaceholder($key,$value);
}
Then you should be able to access them:
&where=`{[[*press-release-date]]:[[*press-release-date:strtotime:date=`%Y`]:isequalto:`[[+year]]`]}`
at a guess... not tested.:)
You can try tvFilters instead. But you will have to translate your [[+year]] into your press-release-date date format and limit search inside intertleave:
&tvFilters=`press-release-date>=[[+year:dec:strtotime]]||press-release-date<=[[+year:strtotime]]`
http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters+%28Output+Modifiers%29
http://rtfm.modx.com/display/revolution20/Date+Formats
http://ru2.php.net/strtotime
I've got question about program architecture.
Say you've got 100 different log files with different formats and you need to parse and put that info into an SQL database.
My view of it is like:
use general config file like:
program1->name1("apache",/var/log/apache.log) (modulename,path to logfile1)
program2->name2("exim",/var/log/exim.log) (modulename,path to logfile2)
....
sqldb->configuration
use something like a module (1 file per program) type1.module (regexp, logstructure(somevariables), sql(tables and functions))
fork or thread processes (don't know what is better on Linux now) for different programs.
So question is, is my view of this correct? I should use one module per program (web/MTA/iptablat)
or there is some better way? I think some regexps would be the same, like date/time/ip/url. What to do with that? Or what have I missed?
example: mta exim4 mainlog
2011-04-28 13:16:24 1QFOGm-0005nQ-Ig
<= exim#mydomain.org.ua** H=localhost
(exim.mydomain.org.ua)
[127.0.0.1]:51127 I=[127.0.0.1]:465
P=esmtpsa
X=TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32
CV=no A=plain_server:spam S=763
id=1303985784.4db93e788cb5c#mydomain.org.ua T="test" from
<exim#exim.mydomain.org.ua> for
test#domain.ua
everything that is bold is already parsed and will be putted into sqldb.incoming table. now im having structure in perl to hold every parsed variable like $exim->{timstamp} or $exim->{host}->{ip}
my program will do something like tail -f /file and parse it line by line
Flexability: let say i want to add supprot to apache server (just timestamp userip and file downloaded). all i need to know what logfile to parse, what regexp shoud be and what sql structure should be. So im planning to have this like a module. just fork or thread main process with parameters(logfile,filetype). Maybe further i would add some options what not to parse (maybe some log level is low and you just dont see mutch there)
I would do it like this:
Create a config file that is formatted like this: appname:logpath:logformatname
Create a collection of Perl class that inherit from a base parser class.
Write a script which loads the config file and then loops over its contents, passing each iteration to its appropriate handler object.
If you want an example of steps 1 and 2, we have one on our project. See MT::FileMgr and MT::FileMgr::* here.
The log-monitoring tool wots could do a lot of the heavy lifting for you here. It runs as a daemon, watching as many log files as you could want, running any combination of perl regexes over them and executing something when matches are found.
I would be inclined to modify wots itself (which its licence freely allows) to support a database write method - have a look at its existing handle_* methods.
Most of the hard work has already been done for you, and you can tackle the interesting bits.
I think File::Tail is a nice fit.
You can make an array of File::Tail objects and poll them with select like this:
while (1) {
($nfound,$timeleft,#pending)=
File::Tail::select(undef,undef,undef,$timeout,#files);
unless ($nfound) {
# timeout - do something else here, if you need to
} else {
foreach (#pending) {
# here you can handle log messages depending on filename
print $_->{"input"}." (".localtime(time).") ".$_->read;
}
(from perl File::Tail doc)
I’m writing a cucumber test where I want to get the HTML in an element.
For example:
within 'table' do
# this works
find('//tr[2]//td[7]').text.should == "these are the comments"
# I want something like this (there is no "html" method)
find('//tr[2]//td[7]').html.should == "these are the <b>comments</b>"
end
Anyone know how to do this?
You can call HTML DOM innerHTML Property:
find('//tr[2]//td[7]')['innerHTML']
Should work for any browser or driver.
You can check all available properties on w3schools
This post is old, but I think I found a way if you still need this.
To access the Nokogiri node from the Capybara element (using Capybara 1.0.0beta1, Nokogiri 1.4.4) try this:
elem = find('//tr[2]//td[10]')
node = elem.native
#This will give you a Nokogiri XML element
node.children[1].attributes["href"].value.should == "these are the <b>comments</b>"
The last part may vary for you, but you should be able to find the HTML somewhere in that node variable
In my environment, find returns a Capybara::Element - that responds to the :native method as Eric Hu mentioned above, which returns a Selenium::WebDriver::Element (for me). Then :text gets the contents, so it could be as simple as:
results = find(:xpath, "//td[#id='#{cell_id}']")
contents = results.native.text
if you're looking for the contents of a table cell. There's no content, inner_html, inner_text, or node methods on a Capybara::Element. Assuming people aren't just making things up, perhaps you get something different back from find depending on what else you have loaded with Capybara.
Looks like you can do (node).native.inner_html to get the HTML content, for example with HTML like this:
<div><strong>Some</strong> HTML</div>
You could do the following:
find('div').native.inner_html
=> '<strong>Some</strong> HTML'
I ran into the same issue as Cyril Duchon-Doris, and per https://github.com/teampoltergeist/poltergeist/issues/629 the way to access the HTML of an Capybara::Poltergeist::Node is via the outerHTML property, e.g.:
find('//tr[2]//td[7]')['outerHTML']
Most of the other answers work only in Racktest (as they use Racktest-specific features).
If your driver supports javascript evaluation (like Selenium) you can use innerHTML :
html = page.evaluate_script("document.getElementById('my_id').innerHTML")
If you're using the Poltergeist driver, these methods will allow you to inspect what matches:
http://www.rubydoc.info/gems/poltergeist/1.5.1/Capybara/Poltergeist/Node
For example:
page.find('[name="form-field"]').native.value == 'something'
try calling find('//tr[2]//td[10]').node on it to get at the actual nokogiri object
Well, Capybara uses Nokogiri to parse, so this page might be appropriate:
http://nokogiri.org/Nokogiri/XML/Node.html
I believe content is the method you are looking for.
You could also switch to capybara-ui and do the following:
# define your widget, in this case in your role
class User < Capybara::UI::Role
widget :seventh_cell, [:xpath, '//tr[2]//td[7]']
end
# then in your tests
role = User.new
expect(role.widget(:seventh_cell).html).to eq(<h1>My html</h1>)