This is probably a fairly unique situation, however I am writing some custom code for myBB. It is essentially a small CMS whereby part of it allows users to define blocks and block areas and fill those block areas with code.
The way I want this to function is that the user creates a block area and then defines its position inside a template. As the user can define any block name they want and place them in any area they want, I am having trouble getting my head around just how to handle this in code.
My thoughts were that I could have the user define a variable in their template named block_blockarea_name, I could then grab that the variable and then parse the name of the variable remove "block_" then use the rest of the name to check for any block that is assigned to that area name. I am trying to do this on a custom page rather than through a plugin itself.
The only other option i have is to have a marker like and use a find and replace on that.
Just wondering if anyone has any ideas or suggestions on a better way to handle this.
Are you asking how to include a template in a custom PHP page on MyBB? I always use this to output things like the header, maybe yours would work in the same way:
<?php
output_page("{$header}");
?>
Related
I have a php application that prints a list of "blocks" to a page. a block includes date, time, title and some other information.
The user needs to be able to add a new "block" to the page, and i'd like the new block to appear in the list of the existing blocks without refreshing the page.
At the moment, i'm doing this with jquery. the user adds a new block, and then jquery inserts a new DOM element, which works fine.
THE PROBLEM: Doing this means that a "block" is rendered in two different ways. One way is with php, when the list is initially printed. the other way is with Jquery, when a new block is added.
Having these two different renders means that whenever i want to change the way a block looks, or add some new field to it, i have to update two different things, the php block and the jquery block.
how can php and jquery to use the same code, to render an individual block?
Without code sample it is hard to give you any real advice. But in general you have a PHP solution which will consist of main PHP script and then a snippet which outputs only a single block. The snippet can be included in a loop with passed values for generating of the main page and later can be same snippet called without any values via AJAX and inserted into DOM. Or second option is to use jQuery function .clone() (https://api.jquery.com/clone/). which can clone the block you want but you will still need to clear all the values, if that is what you want. Or eventually you can include one block with no values and hide it with CSS, and once cloned just change its display from none to block or whatever display property it needs to have.
I am used to creating small php mvc structures etc and relying on passing the id of the item i need to display:
www.asite.co.uk/controller/method/IDnumber
But I see a lot of sites use say the title of a page within the URL.
www.asite.co.uk/controller/this-is-a-title
www.asite.co.uk/controller/i-am-another-section/this-is-a-title
MY question is its easy to get the contents via the ID method but who would you work it to use the text method to retrieve the data / content you require.
Initially I would think of removing the '-' separators then searching the 'title' field say for the result, but not sure if there would be a better/easier way.
Many Thanks
I would like to tell you that the text in url is just name of the page. As I also work in MVC so i know that it is only a page name, the requested data is in post method or stored in sessions which are taken forward to the page and after they are made in use, they are destroyed.
I use a column in my table content called "slug" and find the content searching by this column. This column needs to be unique, of course.
If you just want to display header differently, do it via htaccess:
http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
Hi I am looping through a channel in EE2 and I am outputting all of the fields values but how do I output the fields title that I labeled it in the backend?
CODE:
<!-- Loop to out put a field called Location -->
{exp:channel:entries channel="vacancies" disable="pagination|member_data|categories"}
<p>{vacancy_location}{title}{/vacancy_location}: {vacancy_location}</p>
{/exp:channel:entries}
DESIRED OUTPUT:
<p>Location: Some Location</p>
What worked for me was installing SafeCracker module that is shipped with EE2 and using its {label:} tag
http://expressionengine.com/user_guide/modules/safecracker/index.html#label-my-field-name
You might be able to accomplish this via the SQL query tag, but generally speaking the labels assigned to fields in the back-end are intended to be for use only within the Entry Publishing/Editing screen. The labels for these fields that are seen by the people entering content into the system may not always necessarily be the same labels you want to expose to visitors to your site on the front end.
Like #stoep mentioned, you may have better luck writing a custom plugin to handle this, if writing SQL query tags in your template won't end up as a viable option.
You can't.. The only way to get it is by extracting it from the database. You could write a custom plugin for the task. Another option is to put the field label in the Global Template Variables.
Edit: I quickly created the plugin for you -- you can grab it at https://github.com/Stoep/pi.field_information , place it in third_party/field_information/
Usage:
{exp:field_information channel="news" field_name="news_content" information="field_label"}
{exp:field_information channel="news" field_name="news_content" information="field_instructions"}
I know this is not a drupal forum but, as I’m not getting any response there, I decided to give it a shot here.
I’m creating a web site that accepts custom content from users. So, for that matter, this site has a form and a custom module. Instead of using admin theme, this form is placed inside custom template which is created to have a uniform look with the rest of the pages. As a result, creating form elements through hook_form is out of question. Here’s where my problems lie. As this form uses custom theme, I’m not sure as to what can I do to make drupal know that user is submitting new content data when the form is submitted?
Would I need to use same query string that of content submission page of admin page like - ?q=node/add/page for action attribute of the html form?
(OR)
the only way is to map the url to my custom function and invoke some sort of hook inside of it?
Thanks
You can literally create any markup you want for your form, all you need to do is use the #theme attribute when you define the form. With it you can set theme functions for the form itself and any of the elements.
It is a very bad idea, not to use Drupal's FAPI. It solves so many problems for you, and not using it would be the first step to take if you want to open up a security hole in your site. A development framework like Drupal is not of much worth, if you don't use it's APIs.
Edit:
First thing to do, is to go to Drupal's FAPI reference. You can learn almost everything about the FAPI there.
You could use a template if you want, is just basic Drupal theming, but I would advise against it. It would be a lot more maintainable if you created theming functions for all the elements and used that instead, you could just loop through all the elements and render them like Drupal does, instead of having to edit a template file each you need to change the form. It might be a but more work now, but there's a reward to that work: cleaner and more maintainable code.
In code it looks something like this:
$form['item'] = array(
...
'#theme' => 'theme_function',
);
Doing this, the element will be rendered using the "theme_function". You can see an example of such a theme function for textfields.
I'm working on a web UI control called Folder - it basically mimics Windows Explorer folder - you see a grid of items inside a rectangle and can drag an item around, drop an item inside a different instance of the control, add new items and so on. each item is made of an item template - basically some php code that dictates the look of the item, for example an item template might look like this:
my_item_template.php:
<h3>my item</h3>
<p>i'm an item</p>
when dragging the item i want to replace it with a different template, for example:
my_item_drag_template.php:
<h3>my item</h3>
<p>i'm being dragged</p>
one page may host many different kinds of items, each with its template, its load template, its drop template and so on. my problem is moving all these templates from the server side to the client side.
what i'm doing now - in the server side stage i figure out all the templates that i'll need and include them on the page, hidden (display:none). whenever i need a template (for example when the user starts dragging an item and i need its drag template) i locate it, clone it and use. i'd like to avoid having all this code hidden in my page, maybe store it in a jquery's $(folder).data or something. however, i still need to move it from the php. one option would be to insert the templates to $(folder).data and remove them from the page on page load, but i'd rather avoid it (it adds unnecessary dom manipulation). are there any better ways?
It's certainly an interesting problem, but I don't think you are too far off from a good solution by storing the templates in the dom in a hidden div. Unless you have alot of templates, that generally is a great way to have easy access.
Another option is to ajax request a template when you need it. You can use jQuery's $.load function to get a chunk of html and inject it into an element.
$('<div class="newItem" />')
.load('getTemplate.php?template_id=newItem')
.appendTo('body');
You would obviously have to fill the new element with real data, but you can still do it in a single call.
There is obviously a performance hit by doing this, but the structural gain is pretty significant if you don't mind making the requests. It allows you to define your templates in your backend just like you would a normal page, instead of mucking them all together in a hidden div at the bottom.