How can module know which article is displayed in com_content - joomla3.0

I am developing a module that displays links to articles in a certain category.
Is it possible for the module to know which article (via article id?) is being displayed in the main component (com_content)? In this way, the module could exclude the article currently displayed from the list of article links in the module content.

Using JFactory you can retrieve the current parameters of the page, in this case with this code:
$jinput = JFactory::getApplication()->input;
$id = $jinput->get('id','','INT');
$view = $jinput->get('view','','STRING');
It gives you the view name, that should be article and the id of the article displayed.

Related

Wrong 'View live' url in Wagtail admin message after page creation when using id as slug

I am using a page model 'EventPage', which shall have a slug based on the id of the page. To achieve this, I have modified the full_clean method like this (similar to this question):
class EventPage(Page):
...
def full_clean(self, *args, **kwargs):
super().full_clean(*args, **kwargs)
# set slug to id, if already existing
if self.id is not None:
self.slug = str(self.id)
This seems to work fine in principle. However, after the page is published,the Wagtail admin/pages view shows a message box at the top ('Page ... created and published') with a View live button that links to the wrong url (i.e. using the default slug created from the page title).
In the list of pages below that, the just created page's own View live and Add child page links show the correct page url using the page id. It is just the message box's View live url at the top that needs to be corrected. Here's a screenshot:
How can I get the correct link in the message box at the top as well?
In case it matters, I am currently using Wagtail 2.9, Django 2.2.9 and Python 3.6.
I guess my problem has something to do with the fact that the page id is not known until the page is saved for the first time, and the View live link in the message box somehow uses an initial page.url which is overridden later on.
Any ideas how to solve this?
You could probably achieve this by using Hooks in Wagtail. Hooks are typically used to customize the view-level behaviour of the Wagtail admin and front end. I would suggest overwriting the button functionality this way, or possibly removing the existing button and adding your own new one in. More info in the docs: https://docs.wagtail.io/en/latest/reference/hooks.html
For anyone ending up here, the solution was given in the accepted answer to a similar question here: Wagtail 'View live' button provides wrong url after page creation while using id as slug.
In short: use Django signals instead of hooks, i.e. here a the post_save signal for EventPage.
For documentation purposes, I'm repeating here the solution from the linked question, slightly adjusted. All credits and thanks go to gasman.
Create following signal in the calendar app, calendar/signals.py:
from django.db.models.signals import post_save
from django.dispatch import receiver
from .models import EventPage
#receiver(post_save)
def set_number_and_slug_after_event_page_created(sender, instance, created, **kwargs):
if issubclass(sender, EventPage) and created:
page = instance
page.number = page.slug = str(page.id)
page.save()
new_revision = page.save_revision()
if page.live:
new_revision.publish()
And, if not yet done, register signals in the corresponding calendar/apps.py config:
from django.apps import AppConfig
class CalendarConfig(AppConfig):
name = 'calendar'
def ready(self):
from . import signals
This worked like a charm for me.

Redirect to an external page from a specific article - Drupal 7

I'm very new with drupal.
I have a blog, List of posts.
I need redirect a specific post to a specific external webpage, Is this possible ?
By example: I need to redirect the post (with the arrow red) to www.facebook.com/somePage. (if it's possible in other tab)
But the other posts should be redirect normally to its internal pages.
In this moment I have this configuration:
Any suggestions?
Method 1
Add a URL Redirect pointing from the 'node/#' URL to your external URL.
Render View as you have it now, and when you click the article Title it'll send you to the external page.
Method 2
Install the 'Link' module.
Add a 'Link' field to your Content Type. Configure the link field to open links in a new window, and so on.
Add that new field to your View. Set it to not appear in display, so it can be used later. Move this link above your Title Field in the View, because the order matters.
Edit the Title field settings and use the Link field value as a Token for the Title field.

Where to Place Navigation in Joomla Component Development

I am developing a component 'com_datamanager' with an "Admin Dashboard" using ElaAdmin HTML5 Admin Dashboard Template. I have been able to create a simple component with multiple views without the dashboard template and it works.
But now I am stuck at how to add the 'dashboard theme' and which section whether in the view.html.php or tmpl/default to place all the "sidebar navigation"
The navigation will hold a link to all the various views of the component such as create, edit, delete, messages, product details, product list etc and it must also appear on all the above mentioned views.
I will be glad if someone can help me. thank you
Follow below steps
Create helper file of component if you it is not already there and paste below code in your helper file of component. If file is already there only past function part.
class MyComponentHelper
{
public static function addSubmenu($vName = "")
{
JHtmlSidebar::addEntry(
JText::_('Product List'),
'index.php?option=com_mycomponent&view=products',
$vName == 'products'
);
JHtmlSidebar::addEntry(
JText::_('Product'),
'index.php?option=com_mycomponent&view=product',
$vName == 'product'
);
}
}
Now go to yours views/dashboard's view.html.php file and paste below code before the display method call.
MyComponentHelper::addSubmenu('products');
Same code snippet will go in the product view also just change the view
Let me know if you face difficulties in this. It would be more help full if you post components file structure here.

AngularJS set title and description in head when populating content from JSON

Before I go and do this in Jquery out of frustration I figured I would ask what the angular way is?
I'm building an AngularJS site using a model based of the Phonecat tutorial example on the AngularJS site.
I found this method to set the title of a page and can work out how to modify it to do description as well in the app config but this doesn't work when I'm populating pages with content via json. I tried doing it using a ngbind method as well but have yet to find a working solution as I think something to do with the order in which files are loaded is breaking.
For example
when('/faq', {
templateUrl: 'sub_pages/articles.html',
title: 'Landing page title goes here, not to big a deal'
}).
when('/things-to-do/:activityID', {
templateUrl: 'sub_pages/activity-detail.html',
controller: 'activityDetailCtrl',
title: 'If I put a title here it will be the same on all of these pieces of content'
}).
What method can I use in order to set title on both the landing pages and also the pages which draw their content from a JSON feed?
EDIT - ANSWER BELOW
After about 2 days of bashing my head against a wall trying to work this one out it's actually quite simple and works for both static pages and templates with dynamically loaded content.
Inside the view pages (html that loads inside of ng-view) add a couple of divs (you can put this anywhere really) and then inside them you need to load in ng-init.
ng-init="$root.title = path.to.title"
ng-init="$root.description = path.to.description"
This will set the title and description on the root scope. The "path.to." is just an example path to content in json, you can replace this with plain text as well which is how I deal with landing pages.
Then on the index.html or what ever page your app is based on inside the head you just need to load in.
Your Page Title
This will automatically set your page title and description meta tags and you can pretty much use this formula for any other meta data you need to create.
I haven't tested this yet with Prerender.io or any other cache service but will do some checks and post the results here.
Something like
$document[0].title = "xyz";

CakePHP: Reusable content blocks and MVC

I'm trying to learn CakePHP by building a simple CMS app, it was going well but as I'm adding more, I'm getting a bit confused by the MVC structure.
In addition to my Posts, I have created a simple model for 'Content Blocks' (basically an admin editable title and content field) that I want to display as elements within other pages of my site.
To help explain:
My Posts controller has an index action that lists out all of the blog posts. In the view for that action I also want to pull a specific 'content block' from the database and display it at the top of the page.
Another example would be an admin-editable 'about' blurb that appears in the footer of every page.
Lastly, in a similar fashion to the Wordpress text widget or Magento static block, I'd like to prevent 'content blocks' being directly accessible (i.e. domain.com/content_blocks/view/id)
What is the ideal way to achieve this whilst staying true to CakePHP and MVC convention?
I've had several stabs at it (such as using requestAction in an element) but have only succeeded in getting more confused.
The way I would do it is as you suggested with a request action inside an element because that won't be directly accessible through the URL. So you would create a view inside the elements folder:
app/View/Elements/block.ctp:
<?php $sidebar = $this->requestAction(array(
'controller' => 'ContentBlocks',
'action'=> 'viewBlock',
'yourtitle'
));
// layout your block here
?>
app/Controller/ContentBlocksController.php
public function viewBlock($title) {
return $this->ContentBlock->findByTitle($title);
}
Then you can see this post for how to do caching with the element and requestAction: http://mark-story.com/posts/view/how-using-requestaction-increased-performance-on-my-site
Also, you might want to checkout Croogo, which has a lot of the functionality you are looking for and more already built in: http://croogo.org/

Resources