I have one app having few doctypes. Also, in same app, I have created one web page that does not require login. So, I can access it from http://localhost:8080/home.
Now, I want home page with query string params e.g. http://localhost:8080/home/aaa OR http://localhost:8080/home/bbb where aaa & bbb are query string params. So, how can I specify the same and where? urls with params also land to home page only and then want to perform some action based on params.
âaaaâ and âbbbâ are query string params value. there will be only one param. also, issue is that I want nice urls, so http://localhost:8080/home/aaa should go to home page only. But , for now it is considering home/aaa as another page, and so gives âpage missing or movedâ error.
Can anyone help into this?
Actually I want to make get request with parameter with nice url like /home/value1. i.e. it should map to home?p1=value1 where param 1 is value for parameter p1. I want it should land to home page only and javascript on page will extract params and do further as per my need.
But just now /home/value1 tries to find page âvalue1â considering home as directory. And so gives page is missing error.
You can use frappe.get_route()[1] to extract the value aaa or bbb or whatever value you pass there.
In my use case, I wanted to render a custom page and fetch the data for the specific ID passed in.
Here are my steps (Frappe v13, ERPNext v13, with a custom app):
Create a custom page (Go to Desk, search for Page List, Create New Page)
Edit the JS within your page directory. Here is a snippet of mine:
frappe.pages['item-detail'].refresh = function (wrapper) {
new ItemIDDetail(wrapper);
}
let get_item_by_id = async (item_id) => {
console.log(item_id);
// Call API here, or do whatever you need to do
}
ItemIDDetail = Class.extend({
init: function (wrapper) {
this.page = frappe.ui.make_app_page({
parent: wrapper,
title: 'Item ID Detail',
single_column: true
});
this.make();
},
make: async function () {
let item_id = frappe.get_route()[1]; //If you call /app/item-id-detail/34223, item_id will be 34223
let item = await get_item_by_id(item_id);
this.item = item; // Passing this as context to the rendered template
$(frappe.render_template('item-id-detail', this)).appendTo(this.page.main); //Template to render to
}
});
Create a HTML file inside your page dir, and name it item-id-detail.html
This is what will be rendered.
Proceed to render the context data within your item-id-detail.html file