Search
Other Sourcerer questions
Forum

Get current joomla article id (Joomla4)

Marc's Avatar Marc
Hey RegularLabs-Team,

i need to calculate some data from custom fields on a Joomla4 website.

The first step would be to get the active joomla article-ID . How can I do that with Sourcerer?

Best regards and thank you for your great extensions

Marc
Marc's Avatar Marc
Hey Peter,

thank you for the answer, I get the following error:

Warning: Undefined property: stdClass::$id in /.../tmp/regularlabs/21876_cab31b861fa340be49d6c3b86810b279 on line 10
Peter van Westen's Avatar Peter van Westen ADMIN
Are you using the php code inside an article?
Please post a rating at the Joomla! Extensions Directory
Peter van Westen's Avatar Peter van Westen ADMIN
(Or inside content loaded on an article page)
Please post a rating at the Joomla! Extensions Directory
Marc's Avatar Marc
Yep. But the template for the article is generated with the Yootheme Pro Builder - maybe thats the problem?
Peter van Westen's Avatar Peter van Westen ADMIN
Yes, that most likely is the issue.
Please post a rating at the Joomla! Extensions Directory
Marc's Avatar Marc
Okay, I see.

I tried to work around it with including a php file in the Yootheme Builder and then echo the article ID
{source}<?php
   include JPATH_SITE.'/folder/file.php';
?>{/source}
echo $article->id;

...but I get the same error:

Warning: Undefined property: stdClass::$id in /folder/file.php on line 16

I then tried to archieve it thru a module, but after saving it the php tags are stripped. My backend editor is set to "None". If I try to add the code via the "</>Code" button the php tags are also stripped and a strange span is added:
{source}<span style="font-family:monospace;color:#555555;">echo "Test";</span>{/source}
Peter van Westen's Avatar Peter van Westen ADMIN
Sourcerer is meant to be used with a WYSIWYG editor.
See: docs4.regularlabs.com/sourcerer/going-fu...ing-a-wysiwyg-editor

Probably because you are using Yootheme, Sourcerer can't create the $article object, based on the current URL.
Placing your code in an external file doesn't change that (it actually just makes it more certain that the $article object is not available).

Are you trying to use this on normal article pages in Joomla? So are the URLs pointing to an article page?
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