I use the Commerce Kickstart Distribution of Drupal 7. I want to have the searchbar assigned to a different region on the frontpage than on all other sites in my theme. I used the approach shown here: http://saw.tl/drupal/programmatically-manage-drupal-blocks.html
function mytheme_hook_block_info_alter(&$blocks, $theme, $code_blocks)
{
if(drupal_is_front_page()) {
$blocks['views]['-exp-display_products-page']['region'] = "branding";
}
}
This is the function in my template.php. I know that the search bar is created using the views module and is not a "default block".
The name shown in the Block menu for the search bar is Exposed form: display_products-page, the module name and machine name I choosed following this tutorial http://drupalchamp.org/node/166
However, it does not work at all. I do not get any errors or warnings, the block just stays in is default region when I load the front page.
You can use Context module to add blocks to different regions depending on some criteria:
https://www.drupal.org/project/context
Very powerful and easy to use module so I'm advising it.
And if you prefer doing it form code you could grab block's content and print it from template directly, depending on detected page. Something like:
$block = module_invoke('views', 'block_view', 'block_machine_name');
print render($block);
Of course you would execute it conditionally...
Related
I have the issue that one of the pages in a TYPO3 (11.5.20) environment contains dozens of subpages, which would overly extend the HMENU displayed on the frontend. The suggestion by a colleague was to hide all the subpages in said menu and instead display them on a separate menu embedded on the page itself. This basically means we have to make the subpages hidden for only one specific menu, not for all of them, ruling out the possibility to hide the subpages for navigation by the backend.
To have this functionality not just applying to a single, statically defined page, my idea to approach this would be to register a separate page layout for pages with this requirement and somehow configure HMENU in Typoscript to ignore subpages of that given layout. What I found is the itemArrayProcFunc for processing menu arrays; what I would do is to simply return an empty array with it if said page layout applies. I am encountering two problems though:
The function I have defined seems not to get called. I am including the script like in the Typoscript snippet below, but even when deliberately throwing an exception inside, there is no feedback on it whatsover by TYPO3, with the menu displaying all pages as usual. Is that method of inclusion possibly outdated? The official TYPO3 doc dictates USER and USER_INT for registering custom functions, but I'm not exactly sure how to make this work together with itemArrayProcFunc.
Even if the function worked, I'm not sure how to retrieve the layout of the respective parent page, or if it is even possible to retrieve it at all.
I'm assuming there are some major points regarding custom functions within Typoscript I might have missed (to be fair though - TYPO3's documentation is not exactly transpicuous). Could anyone possibly give me a hint on it? Is there maybe even a more elegant way to hide menus from specific pages?
lib.ts (snippet):
includeLibs.user_menuItemArrayProcFunc = EXT:lraffb_intern/Classes/MenuItemArrayProcFunc.php
lib {
...
20 = HMENU
20 {
stdWrap {
outerWrap = <nav class="navigation">|</nav>
}
entryLevel = 0
1 = TMENU
1 {
wrap = <ul>|</ul>
NO = 1
NO {
allWrap = <li>|
wrapItemAndSub = |</li>
itemArrayProcFunc = user_menuItemArrayProcFunc->process
}
ACT < .NO
ACT {
allWrap = <li class="act">|
}
}
2 < .1
3 < .2
4 < .3
5 < .4
}
...
}
MenuItemArrayProcFunc.php:
<?php
class MenuItemArrayProcFunc {
public function process($menuArr, $conf) {
if (PAGE_LAYOUT == 'pagets__left_no_subpages') // retrieve the page layout here somehow
return [];
return $menuArr;
}
}
This basically means we have to make the subpages hidden for only one specific menu, not for all of them, ruling out the possibility to hide the subpages for navigation by the backend.
Well - actually this is the solution you are looking for but just the other way around. Set those pages to hide in menus and then use the includeNotInMenu parameter to still use them in all menus except the one you mentioned.
https://docs.typo3.org/m/typo3/reference-typoscript/main/en-us/ContentObjects/Hmenu/Index.html#includenotinmenu
Depending on a flag (that could be the page layout) you should differ the rendering of menus. That would be easy if you render your menus with FLUID as you can insert conditions in an easier way than in TypoScript.
e.g.: Depending on your condition you render the second level or skip it.
On page rendering you have all fields from pages record, including your flag. When you call the menu partial just remember to insert the flag in the arguments.
I am trying to create a module which has both frontend and backend functionality. Like I need to ask for the city in the home page when the store loads. And all the available cities are entered/managed in backend admin panel.
Before I used to write for only backend things, frontend seems little confusing.
There is a design folder which is completely for theme development.
All the example are little different(https://www.mageplaza.com/magento-2-module-development/,http://inchoo.net/magento-2/how-to-create-a-basic-module-in-magento-2/]2), they have routes.xml, where route_id, and all are defined, but here I don't need any extra route. Need some additional tweaks in frontend pages.
I created module V_name/M_name/adminhtml/block controllers etc view ...
Guide me how to create a module, which has both front end and backend connection, cities should be entered in admin, they should show on the frontend homepage.
For now, I only managed to edit home page content CMS page by adding some HTML which shows a popup with a dropdown for cities when the page loads.
Since you already have the back-end figured out I will focus on front-end. Also, since all you need to do is populate a list that you already have created this should be easy. I did something like this before and I found it easier to just use JSON to query a list of, in your case the cities, and populate the drop down. I don't believe this is the most 'MVP/proper' way to go, but it is less work then the other ways. (At least for me it is. I always prefer the JavaScript option since it allows for easy future page customization.)
To use the JSON method you need to create a Block with a method like the one below. You will see that you will also have to create a Resource Model (I'm not going to go over creating the Resource Model or the details of Blocks since there are much better resources than me already online that will go into every single detail you need.). Once this is complete you can access the data straight from the .phtml page in an easy to use JSON array.
First you need to make sure you are now structuring your Modules properly. The new Block below should be in a structure like this...
app/code/<VENDOR>/<MODULE>/Block/Wrapper.php (or whatever you name it)
The admin Blocks should be in the structure below, which it sounds like you are already know how to do.
app/code/<VENDOR>/<MODULE>/Block/Adminhtml
Create your Block and add a method to create a JOSN array like below...
public function getCityList()
{
$city_array = array();
/** #var \<VENDOR>\<MODULE>\Model\ResourceModel\City\Collection $collection */
$collection = $this->_cityCollectionFactory->create();
$collection->addFieldToFilter('active','1')->addFieldToSelect(['city_id', 'city']);
$collection->getSelect()->order(array('city ASC', 'city_id ASC'));
$count = 0;
foreach ($collection as $model)
{
$city_array["$count"] = $model->getData();
$count++;
}
return \Zend_Json::encode($city_array);
}
FYI... The foreach loop in the code above is weird and uses $count because I needed to do some tricky things to get something to work.
Then you can create the Block in your .phtml file to access the data via javascript.
<?php
$block_obj = $block->getLayout()->createBlock('<VENDOR>\<MODULE>\Block\Wrapper');
?>
<script type="text/javascript">
window.citylistJson = <?php echo $block_obj->getCityList() ?>;
</script>
i am clearly missing something, but i can't figure out what. I am developing site on Typo3 CMS v7.6.10. I included my extension configuration in TS template.
In \Configuration\TCA\Overrides\pages.php:
<?php
defined('TYPO3_MODE') or die();
// Add pageTSconfig
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerPageTSConfigFile(
'/**/', // my extension
'Configuration/PageTS/pages.ts',
'My special config'
);
In \Configuration\PageTS\pages.ts: (from question here)
TCEFORM.pages {
layout.altLabels.0 = Normal
layout.altLabels.1 = Startpage
layout.altLabels.2 = Landing page
}
After clearing all cache, reinstalling extension nothing had changed in Edit page - Appearance - Frontend Layout drop down. Am i wrong and this configuration is for something else? This is just an example of me using TCEFORM.pages, my attempts to do something with other elements not working too. Do i need to include registered config file? If so, nothing appears in my typoscript template include options.
I am not sure if you did this but
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerPageTSConfigFile()
"only" registers a PageTSConfig file for the selection in the page property. To include it you have to go to the properties of a page in the resources tab and select your file there (see screenshot). It is then active for this page and all subpages.
As an alternative you could use ExtensionManagementUtility::addPageTSConfig() instead. If you pass the <INCLUDE_TYPOSCRIPT string to that function your PageTSConfig will be loaded on every page.
I'm going crazy with this one. I am trying to change a little bit the pagination style and layout in Joomla. So, I found this file: libraries\joomla\html\pagination.php but I know that pagination is overridden by this file: templates\gk_yourshop\html\pagination.php. Yet, if I modify something in gk_yourshop\html\pagination.php, I can't see the change in the pages. Does joomla cache templates and I have to re-load them (like phpBB)?. I don't understand.
I tried to check if writePagesLinks is called from joomla\html\pagination.php with this:
function getPagesLinks()
{
echo "test";
global $mainframe;
and I can't see the message. I also did this in the other pagination.php file and it's just like I can delete them and it doesn't matter. Can you help me? Thanks!
Looks like I changed it here some time ago:
\libraries\joomla\html\pagination.php
But, that is system file, so i just make a "hotfix" of it.
In Joomla 3.x you can create pagination override from Extensions > Templates > Default Template > Create Overrides > Layouts > Pagination.
The override files are created in "Default Template" "html\layouts\joomla\pagination" folder.
You can edit the override files as per your needs.
Where are you getting WritePageLinks from? That's not one of the supported methods.
http://docs.joomla.org/Understanding_Output_Overrides#Pagination_Links_Overrides
There are four functions that can be used:
pagination_list_footer
This function is responsible for showing the select list for the
number of items to display per page.
pagination_list_render
This function is responsible for showing the list of page number links
as well at the Start, End, Previous and Next links.
pagination_item_active
This function displays the links to other page numbers other than the
"current" page.
pagination_item_inactive
This function displays the current page number, usually not
hyperlinked.
[edit]
You may also want to look at Protostar as an example.
I'm trying to make a custom Taxonomy Term page in Drupal 7. I've created a page--taxonomy.tpl.php file in my templates folder. The file only prints out a message. I now try to force the template file by adding
function template_preprocess_page($variables) {
if (arg(0) == 'taxonomy') {
$variables['template_file'] = 'page--taxonomy-tpl';
}
}
in my template.php, but it won't work. Can you help me? And if I get the custom page working, how do I fetch the nodes with this term (in page--taxonomy.tpl.php)? Thanks in advance.
Try using this in your template.php:
function template_preprocess_page(&$variables) {
if (arg(0) == 'taxonomy') {
$variables['theme_hook_suggestions'][] = 'page__taxonomy';
}
}
You need to pass $variables by reference, so add a & before it
template_file has changed to theme_hook_suggestions in Drupal 7
You don't need the -tpl in the template suggestion unless you want it to be a part of the filename like "page--taxonomy-tpl.tpl.php" which I don't think is what you want.
For more information, check out template_preprocess_page(), theme_get_suggestions() and Working with template suggestions
Not sure if this would meet your requirements, but one of default D7 views - Taxonomy term - emulates Drupal core's handling of taxonomy/term pages. You could just enable it (it would automatically replace Drupal's core taxonomy URLs), and then do whatever you want with it, keeping original page structure, all blocks etc, using Views' page templates (see "Theming information" in "Advanced") and all other bells and whistles...
Since you are using Drupal 7, you could also create a file name "taxnomy-term.tpl.php" and edit according to your needs.
See taxonomy-term.tpl.php
Full control over the taxonomy term page can be obtained using hook_menu_alter() . See https://drupal.stackexchange.com/questions/48420/theming-and-overriding-taxonomy-term-vocabulary-page/111194#111194