I have two kind of user in my portal, a customer user and an agent user.
I want to change the default Homepage of Agent user every time he/she logs in or clicks to a Homepage button to the website instead of the customer's default homepage.ie (Agent Homepage)
Currently, I was able to achieve this through below code:
var userId = AuthenticationManager.AuthenticationResponseGrant.Identity.GetUserId();
var user = await UserManager.FindByIdAsync(userId);
var portal = PortalCrmConfigurationManager.CreatePortalContext();
var usercontext = portal.User;
var context = portal.ServiceContext;
var contact = (from c in context.CreateQuery("contact")
where c["contactid"].Equals(userId)
select c).First();
var isAgentUser = contact.GetAttributeValue<bool>("bh_isagentuser");
if (isAgentUser == true)
{
return Redirect("/agent-home");
}
else
{
return RedirectToLocal(returnUrl);
}
I want to know if there's another workaround for ADX studio to achieve this?
Rather than redirecting to a different web page, you could change what information is displayed on the home page based on the detected user type. A simple example using Liquid would be to include a different web template depending on the user type:
{% if user.bh_isAgentUser %}
{% include "Agent Home" %}
{% else %}
{% include "Default Home" %}
{% endif %}
You would add the different home page rendering logic inside each of the Agent Home and Default Home web templates.
The above Liquid could be inserted into the copy field of the home page, or the home page could be changed to use a web template with this Liquid inside it. This choice would depend on the structural elements of the rendered web page that need to change.
See documentation on the user object, include tag, and web templates for more details.
Related
I recently added a minor feature to the slide out shopping cart on a Shopify site to show the customer how many more items they need to add to their cart to receive free shipping. It works just fine, however the issue is that if a customer updates their quantity from the cart, then the feature doesn't automatically update and show that they qualify for free shipping. The customer would have to refresh the page or go to another page to see the update.
How can I make this automatically update?
{% assign free_quantity = 2 %}
{% assign cart_total = cart.item_count %}
{% assign cart_qty_left = free_quantity | minus: cart_total %}
<p class="tt-cart__add-on-title tt-text-2">
{% if cart_qty_left > 0 %}
You are {{ cart_qty_left }} item away from free shipping!
{% else %}
You've got free shipping!
{% endif %}
</p>
The fastest and easiest solution is to make an AJAX request to the current page and replace the content.
For example:
fetch(window.location.href).then(r => r.text()).then(res => {
const html = new DOMParser().parseFromString(res, 'text/html');
const cartText = html.querySelector('.tt-cart__add-on-title').innerText;
document.querySelector('.tt-cart__add-on-title').innerText = cartText
})
Where we make a request to the current URL address with fetch(window.location.href), then we convert the response to text via .then(r => r.text()).
After that we create a DOMParser of the response text:
const html = new DOMParser().parseFromString(res, 'text/html');
We grab the text from the parsed html targeting the proper element:
const cartText = html.querySelector('.tt-cart__add-on-title').innerText;
And finally we replace the text that is present on the page with the text we got from the response with:
document.querySelector('.tt-cart__add-on-title').innerText = cartText
This should happen on a specific event when you add products to the cart or update them.
I have own plugin in October CMS what have a onFilter() function whats return and displays partials with data. When user click on name it redirect him to a detail page. And when user click back button in browser I want to display his last search.
I tried something like Session::push('data', $data) in onFilter() method and Session::get('data') in onInit() but it didnt work. $data is a list of pubs.
Had anyone same problem?
Edit
public function onFilter()
{
$result =
Lounge::filterLounge($categories, $tags, $regions, $paidIds, $price_from, $search);
Session::put('nameFilter', $result);
return [
'#list' => $this->renderPartial('loungelist::list.htm', [
'list_data' => $result])
];
}
public function getNameFilter() {
$nameFilter = Session::get('nameFilter');
return $nameFilter;
}
In partial .htm
{% set list_data = __SELF__.getNameFilter() %}
{% for lounge in list_data %}
{{ lounge.name }}
{% endfor %}
As #mwilson mentions I would use window.history on the front end with the pushstate() function so that when each filter is changed you push state including query strings before firing to php to get the filtered content. I have done this before and works very well.
You should post more code for us to be more helpful. I am assuming you are using a component. Are you using ajax? Session will do the job.
In your component.php put onNameFilter() event you can push the data into the session with Session::put('nameFilter' $data);. I suggest using more specific labels for your events and keys so I chose 'nameFilter'.
You will want to use a method in your component.php to call the session.
public function getNameFilter() {
$nameFilter = Session::get('nameFilter');
return $nameFilter;
}
Now in your partial.htm you can set the name filter data and access it as long as it is in the session:
{% set nameFilterData = __SELF__.getNameFilter() %}
EDIT TO SHOW REFLECTED CODE
I don't understand how it works the first time. What does your CMS Page look like? How do you show the filter the "first time"?
Your CMS Page has {% component 'something' %} right? Then in your default.htm file you have {% partial __SELF__~'::list %}?
In your partial you will need to display the list_data. Does this show anything?
{% for list in list_data %}
{{ list_data.name }}
{% endfor %}
I want to create a joomla 3.x template which shows a different UI on the homepage than on all the oder pages.
This works fine with the following code:
$app = JFactory::getApplication();
$menu = $app->getMenu();
$lang = JFactory::getLanguage();
$isHomePage = $menu->getActive() == $menu->getDefault($lang->getTag());
When I click on a menu item $isHomePage is "false" and I can show a different layout.
But when I open an article from the featured articles-list on my home-page, the menu item is still the home page but the user does see the article.
How do I get the information, if the user is really on the home page?
As per my understanding, the home page condition getting true on inside page is due to the fact that if an article does not have any menu it gets it from the current menu. So clicking on home page article link carries home page menu id.
There are some alternative that I can suggest -
1) Checking for URL - Check if current URL is equal to site page URL.
$uri = JUri::getInstance();
$currentUrl = trim($uri->toString(),'/');
$homeUrl = trim(JUri::root(),'/');
$isHomePage = $currentUrl == $homeUrl;
2) Check for homepage parameter with inner pages parameters. For example, if your homepage is of the article and having id X, check from request params check option and id param to com_content and id == X.
I hope this might be helpful.
I want to save details in database and retrieve back to same page using Ajax. I added the code for your reference. Kindly share your ideas.
models.py
class Personal(models.Model):
user=models.ForeignKey(User)
name=models.CharField()
dob = models.CharField()
email = models.EmailField()
address1 = models.CharField()
address2 = models.CharField()
country = models.CharField()
state = models.CharField()
city = models.CharField()
Views.py
def profile(request):
userid=request.user.id
personal=JSPersonal.objects.filter(user_id=userid)
return render(request,'registration/profile.html', {'personal':personal})
templates(profile.html)
{% if personal %}
{% for p in personal %}
<p>Name : {{p.name}}</p>
<p>DOB : {{p.dob}}</p>
<p>Email : {{p.email}}</p>
<p>Address1 : {{p.address1}}</p>
<p>Address2 : {{p.address2}}</p>
<p>Country : {{p.country}}</p>
<p>State : {{p.state}}</p>
<p>City:{{p.city}}</p>
{% endfor %}
{%else%}
<p>Click Here to add details</p>
{% endif %}
By clicking the "Here" model form get loaded here there is a space to enter the personal details.Here I need to store details in database and return back to same page once I click submit button in the model form. Only particular content get loaded not whole page.
The basic idea is that you put an element with an ID around the data that will change, and target that id with a jQuery.load call.
see: Render a django table using ajax
I recommend that you use the forms for such tasks: https://docs.djangoproject.com/en/dev/topics/forms/
In this case, you can easily send your form with jQuery $.post():
$.post('/form/url/', $('form_selector').serialize())
.done(function(data) { ... })
.fail(function(jqXHR) { ... });
A more detailed response:
How to POST a django form with AJAX & jQuery
Use case
I am developing a CMF on top of Symfony2. One of the features will be the support of "widgets": an possibility for end users to add small 'blocks' or 'modules' to a page. Examples:
A small login form
A list of products
Some photo's from a gallery
A shopping cart
The idea is that most of those widgets will link to to normal, full page Routes/Controllers.
For example: a user want a list of popular products in a sidebar on a content page. The items will link to the normal /product/{name} route of the ProductController. But the list in this case would be a widget. The end user can define where it must be placed, and for example, how much items must be shown.
The behavior of the 'widgets' is the same as regular Symfony2 controllers, it has routes, actions, it renders a view, etcetera. There is a WidgetManager with a catch-all route to load the widgets, configure them and render them in the right place.
I have not that much experience with Symfony2, but I am playing wit it now for more then 3 months. I definitely want to stay with Symfony2, but will need to add some magic to realize some of my ideas.
Question
What is the best way to support rendering multiple controllers (widgets) in one request?
Research
Symfony's TwigExtension "ActionExtension" contains a "render" method, which contains the basic idea:
<div id="sidebar">
{% render "AcmeArticleBundle:Article:recentArticles" with {'max': 3} %}
</div>
(Documentation: http://symfony.com/doc/current/book/templating.html#embedding-controllers)
But it is quite limited. Some problems with this approach:
I cannot configure the 'widgets' before rendering them (for example: $myWidget->set('show_toolbar', false)), I don't want to pass all options as controller action parameters.
It is not possible to use template inheritance. I need this for example for 'injecting' the asset references (javascript/css) in de base <HEAD> block.
What I want
I want the following code to work (this is a simplified example):
// Serius\PageBundle\Controller\PageController.php
// executed by a catch-all route
public function indexAction($url) {
// load CMS page, etc
$widgets = $this->loadWidgets($page); // widgets configuration is stored in database
// at this point, $widgets is an array of Controller *instances*
// meaning, they are already constructed and configured
return $this->render("SeriusPageBundle:Page:content.html.twig", array(
'widgets' => $widgets
));
}
Serius\PageBundle\Resources\views\Page\content.html.twig
{% extends 'SeriusPageBundle::layout.html.twig' %}
{% block content %}
{% for widget in widgets %}
<div>
{% render widget %}
<!-- Of course, this doesn't work, I would have to create my own Twig extension -->
</div>
{% endfor %}
{% endblock %}
An example of a widget template:
{% extends '::base.html.twig' %}
{% block stylesheets %}
My stylesheets
{% endblock %}
{% block body %}
This is a shoppingcart widget!
{% endblock %}
How can I achieve this? Do someone have experience with anything like this? I already looked at the Symfony CMF project, but it has no support for this (as far as I could find out).
I have something similar going around and I think that this code will help you. In chosen template you get the variables with the names of blocks.
public function render()
{
$modules = $this->moduleService->getModules();
foreach($modules as $m){
$templateName = $m->getTemplateName();
$template = $this->twig->loadTemplate($templateName);
$blockNames = $template->getBlockNames();
foreach($blockNames as $b){
if(isset($this->blocks[$b]) == false)
$this->blocks[$b] = '';
$this->blocks[$b] .= $template->renderBlock($b, array('a' => 'aaa', 'b' => 'bbb'));
}
}
$content = $this->twig->render('Admin/index.html.twig',$this->blocks);
return new \Symfony\Component\HttpFoundation\Response($content);
}
I know this is old, but if anyone is looking for something like this the SonataBlockBundle might be your solution.
https://github.com/sonata-project/SonataBlockBundle