Search
Other Articles Anywhere questions
Forum

user:name works fine but how to get a User Custom Field

Marc's Avatar Marc
Hi Peter & co,

I hope you are fine (long time no see 🙂 )

One question:
user:name
,
user:lastvisitDate
etc do work fine as mentioned on docs4.regularlabs.com/articlesanywhere/data-tags/user-data

But I needed to fetch a User Custom Field, like
country
for example.
I tried
user:country
and even
country
(since an alias of a CF must be unique, even across all Components as I discovered) but it does not seem to work.

So
- did I miss the correct syntax?
- or if indeed it is not possible atm, could this feature be added?

Txs!

Marc
Peter van Westen's Avatar Peter van Westen ADMIN
At the moment, no, there is no built-in way to get custom field values of users or categories or other related data that is not the article itself.
Please post a rating at the Joomla! Extensions Directory
Peter van Westen's Avatar Peter van Westen ADMIN
What you could do is create a layout for the user that displays whatever data you want, then call on that layout via Articles Anywhere:
docs4.regularlabs.com/articlesanywhere/data-tags/user-data

That will require you to put the necessary php logic in the layout, of course.
Please post a rating at the Joomla! Extensions Directory
Marc's Avatar Marc
Txs for the hint Peter
Peter van Westen's Avatar Peter van Westen ADMIN
I have been working on a new extension: Users Anywhere

Please try the latest development version from:
download.regularlabs.com/dev/UsersAnywhere-v0.1.0-dev-PRO.zip

It should work pretty much the same as Articles Anywhere.


Example with single users by id and outputting custom media field.
{user id="123"}[my-profile-image-field width="50"] [name] ([username]){/user}

Example with multiple users by usergroup and outputting profile data:
{users usergroup="Administrator"}- [name] ([address1, [postal-code], [city]]){/users}

There is no editor button (yet).
Let me know if it works as expected...
Please post a rating at the Joomla! Extensions Directory
Marc's Avatar Marc
Ooooh, that is *really, really* nice! 🙂

Here is the feedback of my testing (we are almost there though):

1. warnings upon installation
Warning
JInstaller: :Install: File does not exist /home/abcdef/public_html[TMP]/install_66deab4b5f11b/packages/j4/plg_system_usersanywhere/js
JInstaller: :Install: File does not exist /home/abcdef/public_html[TMP]/install_66deab4b5f11b/en-GB/en-GB.pkg_usersanywhere.sys.ini


2. upon using, I get the following error
0
Class "RegularLabs\Library\User" not found

Home Page
Call Stack
#	Function	Location
1	()	JROOT/plugins/system/usersanywhere/src/Users.php:159
2	RegularLabs\Plugin\System\UsersAnywhere\Users->getCurrentUserValues()	JROOT/plugins/system/usersanywhere/src/Users.php:926
3	RegularLabs\Plugin\System\UsersAnywhere\Users->setFilterValues()	JROOT/plugins/system/usersanywhere/src/Users.php:113
4	RegularLabs\Plugin\System\UsersAnywhere\Users->__construct()	JROOT/plugins/system/usersanywhere/src/PluginTag.php:309

3. syntax

Just a few remarks about your syntax examples above (just in case somebody would copy-paste them as such):

3.1.
{user[u]}[/u]
and not
{user[u]][/u]

3.2.
{users[u]}[/u]
and not
{users[u]][/u]

3.3.
{/user[u]s[/u]}
(and not
{/user}
) when using
{users}
Peter van Westen's Avatar Peter van Westen ADMIN
Thanks. Sorry for the issues. It was all a bit of a middle-of-the-night push thing. I'll work on it later today.
I corrected the syntax stuff in my reply.
Please post a rating at the Joomla! Extensions Directory
Peter van Westen's Avatar Peter van Westen ADMIN
Can you try with the new file?
download.regularlabs.com/dev/UsersAnywhere-v0.1.0-dev-PRO.zip
Please post a rating at the Joomla! Extensions Directory
Marc's Avatar Marc
Hi Peter,
Txs again very much!

1. installation went fine this time (no warning)
2. and so far it seems to work. I tested it with the following code (and I will keep testing it further)
2.1. [name] did work for example
2.2. the filter on usergroup is correctly applied
2.3. the Custom Field [user-country] is correctly fetched

{users usergroup="Super Users"}

[name] - [user-country]

{/users}
Peter van Westen's Avatar Peter van Westen ADMIN
Thanks!

I added some code to prevent the Profile plugin fields from being interpreted if that plugin is not enabled.
Please post a rating at the Joomla! Extensions Directory
Marc's Avatar Marc
Good idea. Indeed, for security reasons no one should be allowed to display Users in the front-end unless authorized (so certainly not when playing with the url for instance).

Users are more "touchy" than Articles (getting to know the usergroups, the emails, ...)
Marc's Avatar Marc
Hi Peter!

I have just finalized a more sophisticated example
- with filtering on native field like usergroup
- with filtering on custom field like visible
- with ordering
- with "if" and "else" for custom fields
- displaying custom fields of course
- displaying also [count]

With other words, so far so good 🙂
Txs for this new extension!
<div class="uk-overflow-auto">
  <table class="uk-table uk-table-striped uk-table-small uk-table-responsive">
	<thead>
		<tr>
			<th style="width: 15%;"><span uk-icon="user"></span> Participant</th>
            <th style="width: 15%;"><span uk-icon="tag"></span> Position</th>   
			<th style="width: 25%;"><span uk-icon="home"></span> Institute</th>
        	<th style="width: 10%;"><span uk-icon="world"></span> Country</th>
        	<th style="width: 20%;"><span uk-icon="list"></span> SFP Session</th>
        	<th style="width: 15%;"><span uk-icon="list"></span> Workshop</th>
		</tr>
	</thead>
	<tbody>
      {users usergroup="Super Users" ordering="name ASC" visible="Yes"}
		<tr>
			<td>[count]. [title] [name]</td>
            <td>[current-position]</td>
        	<td>[user-institute]</td>
            <td>[user-country]<br><br></td>
        	<td>{if sfps-list}[sfps-list]{else}-{/if}</td>
        	<td>{if workshops-list}[workshops-list]{else}-{/if}</td>
		</tr>
	 {/users}
  </tbody>
</table>
</div>
Peter van Westen's Avatar Peter van Westen ADMIN
Thanks!

See 2 new settings in the system plugin:


If you switch them off, then [username] and [email] will remain untouched.

download.regularlabs.com/dev/UsersAnywhere-v0.1.0-dev-PRO.zip
Please post a rating at the Joomla! Extensions Directory
Peter van Westen's Avatar Peter van Westen ADMIN
PS: Those settings will disable the handling of those pieces of data altogether, so also not usable in the filters and if tags.
Or would it be better to allow those in the filters and if tags, and output the data tags as empty?
Please post a rating at the Joomla! Extensions Directory
Marc's Avatar Marc
Gosh, I had not thought yet of going in the Plugin itself to see all the parameters 😁
I have installed the latest version and checked the Plugin parameters.

My first feeling about your question is:

Given the fact that we can restrict the use of Users Anywhere to the selected User Groups, well I think that it is reasonable
- to allow the use of [username] and [email] in Filters and If Tags
- given the fact that they will not be displayed if the parameter is set so
Peter van Westen's Avatar Peter van Westen ADMIN
Done.

PS: The User Group restrictions only have an effect on the output of articles, based on the author of that article. It off course doesn't prevent the user from placing the code in the articles. It also doesn't prevent the use in other types of content (like a forum). But those can be globally switched off on the component level (not user group level).
Please post a rating at the Joomla! Extensions Directory
Peter van Westen's Avatar Peter van Westen ADMIN
More on the development of Users Anywhere will be posted here:
regularlabs.com/forum/articlesanywhere/5...sers-anywhere#113429

Please post any testing results and feedback there...
Please post a rating at the Joomla! Extensions Directory
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription