0

I want to create a custom module that shows the content of an article, I need to know two things:

1) What form field should I use in order to select the article that I want to use from the backend?. I've checked this : https://docs.joomla.org/Standard_form_field_and_parameter_types but I still don't know which should I use

2) How can I retreive the article in my main php?, maybe this is related to the form field in the above question

Thanks

2

There is not a standard form field for articles, but there is the SQL field which allows querying the database and returns a dropdown list with the results, which could be sufficient for a simple implementation.

There is a really helpful documentation page for it with many examples: https://docs.joomla.org/SQL_form_field_type

Example XML field definition:

<field
    name="articleid"
    type="sql"
    default=""
    label="Select an article"
    query="SELECT id, title FROM #__content"
    key_field="id"
    value_field="title"
    />

Then later in your module, you will have the articleid by the module's parameters. You can load the article like so:

$article_id = $params->get('articleid');
$article = JTable::getInstance("content");
$article->load($article_id);

//var_dump($article); 
//this is the whole article object you have loaded.

// You can echo properties like so:
echo $article->title;
echo $article->introtext;
  • Hello thanks for your answer, it was very helpful, but I think that I found a simpler way, I wanted to show an Article inside my module in order to make the content of my module easy to customize, that was the only reason, but after I read about the "Standard from fields" once again, I found that there is the "Editor field", that shows a WYSIWYG editor, that works for me, but is lacking one thing : when you create or edit an article, there is a button at the bottom that allows you to add and upload image, How do I add that button?? is there a way?? Thanks – Giovanni El Zelah May 13 '17 at 1:24
  • @GiovanniElZelah what you say here is a different thing than what you initially asked. If you want to write html code with the editor inside a module, there is already the custom html module. For using the editor form field, check here: joomla.stackexchange.com/questions/5237/… – FFrewin May 13 '17 at 5:54
  • You should also check if user has permissions to read this article. – Artur Stępień May 13 '17 at 10:34
  • @FFrewin I am trying to make a modal window module, and I want to make the content of the modal easy to customize, the custom html module don't allow you to write the necesary javascript in order to turn it into a modal, besides this module its not for me, its for somebady else, someone that doesn't know anything about programing or HTML, I just want to make them everything as easy as posible. – Giovanni El Zelah May 14 '17 at 3:09
  • 1
    @GiovanniElZelah - well you realize that your question is different. Compare your last comment here with your question... I want to create a custom module that shows the content of an article, I need to know two things: 1..., 2.... VS I am trying to make a modal window module, and I want to make the content of the modal easy to customize... So this conversation evolves while you are jumping over new requirements or ideas... but we don't have magical powers to guess what you really want, or what direction you' ll take the next moment... – FFrewin May 14 '17 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.