I'm trying to create a link in a Liferay template using Velocity.
My code is the following, based on several examples on the net:
#set ($plid = $getterUtil.getLong($request.get('theme-display').get('plid')))
#set ($u = $portletURLFactory.create($request,"1",$plid,"RENDER_PHASE"))
$u.setParameter("struts_action","/asset_publisher/applyForJob");
yyy
I get the plid value, but my URL will be just ending with $u, it seems that the $portletURLFactory.create() method is not properly interpreted.
Any ideas? Thank you!
Are you trying to do this inside Web Content Template? In that case it will not work because you do not have access to the real http request object. You need to create this link using javascript instead. Here is a code snippet.
<script type="text/javascript">
function createURL() {
AUI().ready('liferay-portlet-url', function(A) {
var renderURL = Liferay.PortletURL.createRenderURL();
renderURL.setParameter("struts_action","/asset_publisher/applyForJob");
renderURL.setPortletId("1");
renderURL.setPortletMode("view");
renderURL.setWindowState("normal");
window.location = renderURL.toString();
});
}
</script>
Go
Related
I am building website using Gatsby and I am fetching some data from my backend. I want to set set global baseUrl for Axios. Normally I will do something like this:
import axios from "axios";
axios.defaults.baseURL = "API_ADDRESS";
But where should I put this in Gatsby to make it global?
in case someone else comes here, the suggestion of mohammed agboola is not accurate, using onInitialClientRender the base url will change to client side url when you refresh the page, in the same file gatsby-browser.js you should be using onClientEntry instead of onInitialClientRender :
export function onClientEntry() {
axios.defaults.baseURL = "YOUR_BASE_URL"
}
Create a gatsby-browser.js file in the root folder of your project, if you don't have one.
and use the lines of code below:
const axios = require("axios").default
exports.onInitialClientRender = () => {
axios.defaults.baseURL = "YOUR_BASE_URL_HERE"
}
The above lines of code set axios baseURL when Gatsby App is rendered to the browser. Hope this answers your question.
I'm quite the noob using Ionic or Angular for that matter. So as a cheat sheet I'm using the ionic-super-starter template (link below).
I am trying to make a get request to my API and it works just find if I'm doing it like this:
this.api.get('user/'+this.user.userId+'/entries?include=stuff&access_token=TOKEN');
but when I put the url params into an object it stops working:
let options = {
'include':'stuff',
'access_token':'TOKEN'
}
this.api.get('user/'+this.user.userId+'/entries', options);
The only error I get is "Unauthorized Request" since the options object including the access token was not appended to the url.
In the ionic-super-starter template the providers/api/api.ts calls .set() for each key in my params object:
if (params) {
reqOpts.params = new HttpParams();
for (let k in params) {
reqOpts.params.set(k, params[k]);
}
}
but according to Angular University this is not possible since "HTTPParams is immutable".
If it really was wrong to do this, I don't believe it would be in the ionic template. Nor would I believe that I would be the first person to come across this issue.
However, I am stuck here so any help would be appreciated.
Link to Angular University:
https://blog.angular-university.io/angular-http/#httprequestparameters
Link to ionic-super-starter:
https://github.com/ionic-team/starters/tree/master/ionic-angular/official/super
I think I figured it out myself:
if I write (in my src/providers/api/api.ts)
reqOpts.params = reqOpts.params.append(k, params[k]);
instead of
reqOpts.params.set(k, params[k]);
it works.
if you are using a loopback API as I am you might have nested objects like:
let options = {
"filter": {
"order": "date DESC"
},
"access_token":this.user._accessToken
};
this won’t work. try instead:
let options = {
"filter": '{"order":"date DESC"}',
"access_token":this.user._accessToken
};
Can someone please explain the context in which port.on and port.emit are used in a firefox extension?
From the official documentation I imagine that this should work:
//main.js
var someData = "Message received";
self.port.emit("myMessage", someData);
self.port.on("myMessage", alert(someData));
but I get
Error: self is not defined.
After attaching this to a defined object like this:
var self = require("sdk/self");
self.port.emit("myMessage", someData);
I get
Error: port is not defined.
If you use the page-mod module to inject a content script into a web page, you then use self.port in the content script to communicate back with main.js. For example:
main.js:
var data = require('sdk/self').data;
require('sdk/page-mod').PageMod({
include: ["*"],
contentScriptFile: [data.url('cs.js')],
attachTo: ["existing", "top"],
onAttach: function(worker) {
worker.port.emit('attached', true);
}
});
cs.js:
self.port.on('attached', function() {
console.log('attached...');
});
For the related documentation, start here:
https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts
I'm trying to use a form to submit to the website so that I can render the website.
this is my form
div.ten.columns#LogModal
h3 Log In
p
a.button(href='#', data-reveal-id='exampleModal') Example modal
div#exampleModal.reveal-modal
h2 Log In
p
form(method='get', action='/Log')
input(type='text', placeholder='Username', name='Username', id='Username')
input(type='password', placeholder='Password', name='Password', id='Username')
input(type='submit', value='Log in', id='LogButton')
script(src='javascripts/foundation.min.js')
script(src='javascripts/app.js')
script
$(window).load(function(){
$("#featured").orbit();
});
And its just going through the server.js like so
app.get('/Log', User.Home);
and eventually renders a webpage like so:
exports.Home = function (req, res) {
res.render('MyHome'); };
and all that results in this error:
Cannot GET /Log?Username=&Password=&LogButton=Log+in
I want it to work without any log in information at this point because its just for demonstration right now. Can anybody help me?
app.get('/Log', User.Home);
In this function, if User.Home is not defined then you will get this error.
Does Home function exist in User model?
Just create one function(lets say 'demoHome') with any name in server.js and call it here like..
app.get('/Log', demoHome);
where demoHome function will be defined as..
var demoHome = function(req, res){ somecode here with proper response or render any page here using res.rendere('path/of/template')};
I have a Controller action and sending a mail in it with something like:
mailService.sendMail {
...
g.render(template: "mailtemplate")
}
in this template file is called _mailtemplate.gsp I use
linktext
But the output is http://action ... that's it! I would expect to have http://www.example.com/action. If I use the same createLink tag in a gsp which is not a template it's working (by the way, email is working fine and all the other stuff in this template is rendered well).
Have you any suggestions on that?
Probably you need absolute link:
linktext
Btw, you can also use ${} syntax there, like:
linktext
QUOTE: I must specify a serverURL in config file, but I want it dynamically
You can probably do as such:
config.groovy:
environments {
development {
grails.serverURL = "http://localhost:8080"
}
production {
grails.serverURL = "http://www.mywebsite.com"
}
}
Then in your service sending the email:
import org.codehaus.groovy.grails.commons.ConfigurationHolder
def baseURL = ConfigurationHolder.config.grails.serverURL
mailService.sendMail {
...
g.render(template: "mailtemplate", model:['baseURL':baseURL])
}
And at last in your link:
linktext
I hope this helps