2 users online. Create an account or sign in to join them.Users
Preview mode?
This is an open discussion with 10 replies, filed under General.
Search
In your XSLT you can use an if statement to test if someone is an admin or an author (logged in) and display all entries.
Check the default navigation.xsl file to see an example of how this is done.
When you filter your entries in XSLT you might get unwanted results for pagination. If correct pagination is important you should create separate datasources for published and unpublished entries. You can then create either a page just for the unpublished entries and set its type to admin that only authors/developers can access this page or you can add both datasources to one page and use an if statement to show unpublished entries to logged in users only.
If you are comfortable with modifying the datasource php file you could modify $this->dsParamFILTERS when $this->_Parent->isLoggedIn() returns true in the grab()-function. Don’t forget to return false in the allowEditorToParse()-function when you modify a datasource.
@klaftertief yes, that’s the kind of problems I am running into. Pagination is only one of them. XSLT doesn’t seem to be the place for doing this unless on small bits like menus etc..
I will try what you mention about the datasource. It seems like the most viable way for this, since what I am really trying to achieve is publishing products in a way that their pages can be previewed during preparation, before hitting the Publish checkbox.
Thanks, T
As it was suggested to modify the datasource file and disable its parsing in the backend, I was wondering if an event would be best suited for this.
Could and event modify-append the WHERE query of a datasource based on logged in status?
Could and event modify-append the WHERE query of a datasource based on logged in status?
Not really, Events and Data Sources rarely communicate with one another. You best bet is to turn the Data Source into a custom DS as klaftertief suggests. You should be able to do this in just a couple of lines of PHP to:
- detect if the user is logged in
- unset the relevant key from the FILTERS property of the DS object
Thanks Nick. I’ll do that now. However if you can come up with a suggestion on how to centralise this sort of switch that would be ace. I am willing to spend some time to get it to work right, but I could really use some help on what would be the best patterns to avoid customising the code of each datasource.
To summarise, what I have so far:
- Pure XSLT switch based on $is-logged-in
- Multiple Datasources (public and admin types)
- Custom mod on each datasource switching queries on isLoggedIn() boolean.
Number 1 creates pagination count problems and other types of headaches. i.e. if I want to iterate through a list of photos (spat out by ds-1) based on the ‘published’ status of some entry in a different section pulled by ds-2. Too hard and too brittle for my taste.
Number 2 creates list continuity problems I imagine. Say I have:
- Item1(public)
- Item2(private)
- Item3(public)
- Item4(public)
- Item5(private)
By using 2 separate DS I would end up with:
- Item1(public)
- Item3(public)
- Item4(public)
- Item2(private)
- Item5(private)
Number 3 is a maintenance chore but at least it generates a consistent output.
I slapped the conditional statement in the constructor. It seems to be passing correctly so far. (bit of pseudocode there…)
UPDATED CODE
There is the Global Parameter Loader extension to add parameters to Symphony’s paramater pool. You can use PHP to create the parameter values. This way you could remove the logged_in logic out of the datasource. But you might run into problems setting up your filters correctly.
Doesn’t the default Symphony Theme have this behaviour? Using purely xslt based on whether the user is logged in (using the events node)?
It does, but I prefer to have XML content filtered to reflect logged-in status. 3 lines of php are easier than brain-melting declarations in XSLT to exclude all entries that contain a certain subnode.
Also, when doing it via PHP, entry counts reflect are consistent with what is shown.
From my limited experience I think XSLT is more suited for transforming rather than filtering content. But maybe I’m just a victim of beginner’s confusion.
Create an account or sign in to comment.
Hi,
Still getting to grips with the system and on top of everything with XSLT intricacies.
Is there a way in Symphony to preview pages when logged in? I have a “published” checkbox field for most sections and would like to show “unpublished” entries only when a user is logged in.
I am already using the login event grabbed from the default workspace, but that forces me to create crazy logic hoops in XSLT if I want to filter and transform related nodes in the XML based on the login status.
I probably missed something, but is there a way to ask symphony to filter entries by login status, before spitting them out to XML?