Page variables in custom data source
This is an open discussion with 2 replies, filed under Troubleshooting.
Search
Hi Nigel not that difficult, to do.
I would however not really use the $param_pool
directly if possible.
If you're extending a SectionDatasource
to keep it simple, all you should need to do is add as many $dsParamFILTERS
as required. In your case all you should need to do is this.
public $dsParamFILTERS = array( 'tags' => '{$ds-news-article.tags:$ds-unit.tags:-1}' );
And when it doesn't find the first variable it will fall back to the second. I added -1 so if none of the datasources return any data, it assumes there is a tag of -1 which will probably not yield any results.
You will also need to ensure that it runs after the other datasources. so just add this line within the __construct
function of your datasource. Most likely the _dependencies
variable is already in this block.
$this->_dependencies = array('$ds-news-article.tags','$ds-unit.tags');
Then of course instead of param pool you access your variables through $this->dsParamFILTERS
also like this you could access $current-page
and other page variables.
Jonathan, thanks so much for your helpful response!
I'm not actually extending SectionDatasource
, but your comment about conditional logic got me thinking along the lines I needed to get this piece functioning. I also appreciate the comments about dependencies, which I hadn't considered at all.
Thanks again.
Create an account or sign in to comment.
I'm creating a custom data source which executes a MySQL query that relies on content from a $param_pool variable. In this case, that's
$param_pool["ds-news-article.tags"]
.I'd like to be able to re-use this data source on a different sort of page. It will behave exactly the same way, except in this case, the variable it needs to grab is
$param_pool["ds-unit.tags"]
.Is there any sort of variable I can call to tell me what other data sources are on the page? Or the
current-page
variable of the page the DS is called from? Really anything would be helpful—I can apply conditional logic and go from there.I know this is a silly question... I was stupidly thinking I could use the php variable
$param_pool["current-page"]
until I thought a little longer about how Symphony puts these pieces together. And now I am just confused—and wondering whether I just need to make nearly-identical data sources that reference different param-pool variables, which seems wasteful.Thanks for any help.