Expression Engine template variable passing - expressionengine

I'm building in Expression Engine 2.3 a user profile system using Solspace's User and Friends modules. They work fine, but I'm having an incredibly difficult time with passing embedded variables around.
I've got a .profile_head template that's called from each template. The profile page, the friends page, the private messaging page, etc. It builds a user navigation, displays the avatar, all the common user stuff. All of this is based off of the user ID passed through {segment_3}. This allows me to display a different user's info by changing this segment.
The problem is doing this makes my URLs far too precise. I can't have users going to /users, they have to go to /users/profile/UID or the best possible scenario is an error page or redirect to the home page.
I tried to solve this problem through variables in my template:
{embed="/users/.profile_head" uid="{segment_3}"}
or......
{embed="/users/.profile_head" uid="{logged_in_member_id}"}
In the .profile_head template file, I can print out {embed:uid} just fine, but when I try to assign it to anything (i.e. a loop or another template), it breaks:
<!-- /users/.profile_head -->
{exp:friends:members member_id="{embed:uid}" dynamic="off" limit="1"}
or.....
{embed="users/.profile_column" uid="{embed:uid}"}
For instance, if {embed:uid} is set as {logged_in_member_id}, I get the following error:
Parse error: syntax error, unexpected T_LNUMBER in /var/www/system/expressionengine/libraries/Functions.php(656) : eval()'d code on line 9
This is line 9:
{if logged_in_member_id == "{embed:uid}"} <span class="this_is_you">This is you!</span>{/if}
I really am at my wits end. I need to be able to use this profile header in templates without requiring a user id in the URL for things like the user messaging and settings pages. But nothing I try seems to be working in the least.

I believe that {logged_in_member_id} is a late-parsed variable, which means it may not be available in some of your tags at the point they're processed - hence it's passed as literally {logged_in_member_id}.
Try using the CURRENT_USER constant instead.

Related

Azure B2C injects different html despite LoadUri having the same html content

I am using custom policies and all is working great except that I do not understand the following wierd behavior of the injected html. I am working on a password reset flow and adapted the starterpack.
In a ContentDefinition and indpendent from the layout version (here 2.1.2, but the problem occurs also for 2.1.0)
<DataUri>urn:com:microsoft:aad:b2c:elements:contract:selfasserted:2.1.2</DataUri>
I get a different injected html based only on whether I use the default page
<LoadUri>~/tenant/templates/AzureBlue/selfAsserted.cshtml</LoadUri>
or my custom one,
<LoadUri>https://mytenant.blob.core.windows.net/b2cweb/selfasserted.html</LoadUri>
But this custom page contains excatly the same html as the AzureBlue one. Specifically,
I navigated to the page /tenant/templates/AzureBlue/selfAsserted.cshtml , copied the html content and pasted it in my custom file in blobstorage.
Expected result
I expect the html page where the id="api" div is injected to be exactly the same if I call the LoadUri one or two. Nothing else in the custom policy files is changed.
Result
If I use the default LoadUri, the cancel button is shown just below the div id="api", as expected for a proper html document format
If I use my custom page, which again contains the same html but lives in blobstorage, the cancel button appears below the continue button in the html (but is rendered on top via css absolute positioning)
Also notice the appeareance of an empty div with class="buttons" at the beginning of the div id="api".
I need to understand what is happening for the purpose of understanding and ideally I would like the generated cancel button to appear just like the default AzureBlue.
I checked out that the old, classic userflow puts the button at the bottom, so it is as if I am using version 1.2.0 but only for my custom page, whereas my content definition is always 2.1.2 or 2.1.1.
Thanks Octopus and please find the same response here.
This is expected because of policy engine and location of storage with predefined CORS server and corresponding linked metadata files for rendering. So please use as best practices provided in the document - https://learn.microsoft.com/en-us/azure/active-directory-b2c/page-layout

Page template - Object reference not set to an instance of an object

I have a page template that has this line of code below:
<div id="<%= CurrentDocument.NodeAlias %>" class="lvl3">
Things work - the id value shows correctly. However, when using the Page Templates module Design tab, there's an error. In Event log, I saw the error message "Object reference not set to an instance of an object". Taking the id snippet out, the error is gone. I'm not sure what the error means and how to fix it. Could you help?
I do need some page-specific unique identifier in there (NodeAlias in this case) for other purposes.
The answer is pretty simple - if you open your page template in Kentico Page Templates application - your CurrentDocument is always null (because you are editing Template itself without specific document).
You could do absolutely the same thing in Pages application with the Design tab. It's also possible to edit all the template properties from there, including the Layout:
Using code blocks on page template layout is not supported. I assume you are using ASCX layout. Moreover your code looks more like a macro - so, maybe you are using HTML layout type? If yes, then the syntax should be {%CurrentDocument.NodeAlias%}
If you are using ASCX layout you may face also this issue: https://devnet.kentico.com/articles/the-controls-collection-cannot-be-modified-because-the-control-contains-code-blocks
Note that in portal engine the life cycle is bit modified, so we cannot ensure the code blocks will work every time - it may work sometimes. It mainly depends on what other web parts/controls and in what order are placed in the page template. I would rather recommend using the workaround from the article.
Or, you can give it a try, with no guarantee, this may work in certain cases, you need to specify the full namespace:
<%= CMS.MacroEngine.MacroResolver.Resolve("{%CurrentDocument.NodeAlias#%}") %>

Chrome extension won't allow get request

I'm trying to create my first chrome extension. Basically I have a simple html page and some javascript that im using to allow users to enter some data, the script will format it correctly and then output it:
<form>
MAC ADDRESS: <input type="text" id="mac" name="macAddress" maxlength="17" >
<button onclick="convert(); return false;">Convert</button>
</form>
Javascript:
function convert() {
var mac = document.getElementById('mac').value; //get string
var mac2 = mac.replace(/\:|-/g,""); //remove colons and dashes
//
//add fullstops after every 4th character, appart from last character.
//
mac2 = mac2.replace(/(.{4})(?!$)/g , '$1.');
//output string
document.getElementById("outputDiv").innerHTML= mac2;
};
My problem is that while this works fine as a normal web page, the get method, to the same page, is not working when I tried to implement it as an extension.
I've followed the tutorials on google's site and the extension is showing up but it doesn't seem to be able to handle get requests. I've tried modifying the manifest file using different suggestions I found on here but still no success.
Theres nothing in the console when I try to debug it (something briefly flickers up when I submit the get request but it doesn't stay up long enough to see what the issue is).
I'd really appreciate it if someone could point me in the right direction with this!
Due to the Content Security Policy applied to extensions:
Inline JavaScript will not be executed. This restriction bans both inline blocks and inline event handlers (e.g. ).
[...]
The inline event handler definitions must be rewritten in terms of addEventListener and extracted into popup.js.
For more info atake a look at the docs.

Contents of h:head are not getting updated while using template in JSF (ICEFACES)

Requirement:
Adding javascript file for a given page (which uses templates).
Details:
After successful login, user is navigated to a page, where he can perform different actions.
I have used common template in all the pages (apart from login page).
The template contains head tag, code for including header, footer and body (in which dynamic content will be included).
I observed that contents of head tag of the template are not getting updated (i.e. title tag, script tag).
The contents of head tag remains same as that of login page and also the URL of my browser.
Can you please let me know the possible cause for above.
It is probably related to the fact partial updates require id of a tag to be updated and html head element does not support id. There is no address in the html to apply update to. Icefaces are using partial updates heavily. You can try to enforce full update upon interaction which triggers changes to head element.

Can I link to an HTML file in my project from a UIWebView?

If I load a string containing HTML into a UIWebView, and that string contains objects (hyperlinks) that are relative to that string, i.e. , where there is some object with id "something," then the link works - click on it and the web view jumps to the referenced object.
What I want is to get navigation to a different file in my project, in other words as though the path to the different file were a URL.
I have found that if the href IS a URL, such as href="http://www.amazon.com", then the link works.
If I put the name of a file, OR the [NSBundle mainBundle] pathForResource: ] of that name, in the href, then the link does not work.
Is there some way I can generate the equivalent of a URL pointing to an HTML file that is in the project, so that an can link to that HTML file?
I found a solution at this link:
How to use Javascript to communicate with Objective-c code?
Essentially, the solution is to implement the UIWebViewDelegate protocol's shouldStartLoadWithRequest method, and "trap" a particular value of scheme. So my links, instead of saying something like:
<a href="http://someplace.location">
are like:
<a href="mylink://#filename.ext">
By catching attempts to load anything with scheme "mylink," I can use:
[[request URL] fragment]
within shouldStartLoadWithRequest, and get the filename.ext. I then release my previous UIWebView, load in the contents of the specified file, and make that the contents of a new UIWebView. The effect is that the links work with normal appearance, even though they are being implemented with my code. I return NO because I don't want the usual loading to take place. If the scheme is NOT mylink, I can return YES to allow normal operation.
Regrettably, I still have no way to jump TO a fragment within a web view. In linking to a real URL, you can say something like "www.foo.org#page50" and jump straight to wherever an object on the new page has an id of "page50." With my method, I can only go to the top of the page.
This is also not going to give me a "go-back" function unless I record the filenames and implement it myself.

Resources