I’m working on a blog like page and I want an about page where the different authors are listed with their image and some other info. Every author has their own MODX user profile so this is where the information should be pulled from.
Probably an array (?) which grabs all user profiles, preferably from a specific user group so I can control which ones are shown and pull the wanted information from there. To make things more specific let’s say I want to grab their Name and their Photo.
What I got so far:
Not too much honestly, I found this post in the old forums which seems to do sort of similar things and changed it as far as I could understand it to:
All of this is in a snippet [[getUserInfo]] but as it is right now it doesn’t do anything. I tried to echo the $username into my markup, but that didn’t show up. Is this the right start to tackle my issue? If so:
Profiles are effectively split into two tables. Username is part of the ‘user’ table and ‘photo’ is part of the profile. It appears you’re querying the profile for the username above which would have lead to nothing being returned.
The two additional variables $quote and $about work fine. I just don’t get the image. The compiled code is empty: <img src=""
Am I missing something?
Update: I added a few more users to the role which is displayed, and oddly one of them has the image shown, so the problem might be somewhere else. Investigating…
Also is this the appropriate way to get a PHP variables output in the HTML structure (by writing the HTML in the snippet)?
Hmmm…one photo working but others not. That is intriguing. Do they all seem to have the same path in the field value? Are the names fairly long perchance?
I don’t see anything you’ve done wrong with the photo field. If the others are working then getting nothing from the photo field seems odd to me.
The best way to manage output is to move the HTML into a chunk. So, create a new chunk and put the HTML in there and give it a name.
Then, put your variables into an array instead and call getChunk with that array:
Then in the chunk, username (and any other fields you’ve set) will be available in a placeholder. Placeholders look like [[+this]]
e.g. <div class="team red"><h3>[[+username]]</h3></div>
While there’s nothing wrong with what you’ve done, it makes it tricky to tweak presentation without messing with logic. The getChunk method is your friend for separating the two.
Let us know where you get to with the similarities/differences in photo paths.
So turns out for some reason the image path wasn’t set anymore within the user profiles (except the one who worked obviously). Not sure why that happened, but will have a lookout for that in the future.
Thanks a ton! You opened up a whole new world for me there, made my day! Always wondered how to combine chunks with snippets until now…
@bobray Now that it’s working I’ll probably keep it as it is, but I will definitely look into that if I need something similar in the future! Thanks alot!
We had enabled this feature for the support sections. But your thread was started in the General section. I’ve enabled it in this section as a test, and we’ll monitor going forward from here to see if it is appropriate for this section.
This thread is incredibly useful for dealing with users of a site.
There seem two key issues that are explained well: Getting the user tables (two tables not one, because of the extended profile), which is obviously important for many purposes.
The second thing is the use of chunks of html in snippets, for the output. This is something Modx does really well, if you know the code.
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.