We have a SaaS product for various clients. Each customer has its own installation in a Virtual Machine. Our user guide has been in Word/PDF. Customer have been able to modify the user guide to add the brand (logo, product name) in the user guide.
Now we want to set up the user guide in Drupal. To move the content of the user guide into Drupal is easy. The challenge is the customization for each customer. We don't want to install Drupal in each Virtual machine and replicate the content.
When someone clicks on "help" in our product they can get to Drupal and we can add parameters for 'client', 'version number' etc. to the URL. Drupal could process this to customize the set up. We can also use the client information for unique login for each client.
I was able to modify the logo by changing $logo in the page template. However, it changes the logo globally for all clients. The latest click to Drupal sets the logo.
I don't know how/where I can set up a logic to customize the logic based on the login. So Client A sees a different logo than client B accessing the same Drupal installation at the same time. In addition we would like to be able to customize the product name in a similar way.
I don't expect any program code (but I would not mind a module). Just some ideas on how to develop this would be great.
This has been the code in the page template. However, the logo changes every time a new client goes to the guide. Is there anything like a session or logoArray[client] feature that I could use to make the logo unique for every client even though many clients access the page concurrently?
<?php
$arglist = drupal_get_query_parameters();
if ( count( $arglist ) > 0 ):
$theme_name = 'bootstrap_ivs7';
$var_name = 'theme_' . $theme_name . '_settings';
$settings = variable_get($var_name, array());
if ( $arglist['logoflag'] == 'logoclient1' ): ?>
<?php if ($logo):
$logo='http://localhost/ivs7/sites/default/files/logo_client1.png';
$settings['logo_path'] = $logo;
variable_set($var_name, $settings);
<?php endif;
else:
if ( $arglist['logoflag'] == 'logoclient2' ):
$logo='http://localhost/ivs7/sites/default/files/logo_client2.png';
$settings['logo_path'] = $logo;
variable_set($var_name, $settings);
<?php
else:
$logo = 'http://localhost/ivs7/sites/all/images/logo_default.png'; ?>
$settings['logo_path'] = $logo;
variable_set($var_name, $settings);
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<?php
<a class="logo navbar-btn pull-left" href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>">
<img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" />
</a>
?>
From a custom module or a theme, you can can implement hook_preprocess_HOOK() to alter the variables of any template. Likely the variables you want to customize per client are all used in the page.tpl.php template, so that would be XYZ_preprocess_page() (where XYZ is the name of your theme or module).
Related
I'm trying to add feature to my website where users will be able upload files in comments.
I'm trying to do that using Advanced Custom Fields plugin.
Some parts of job are done. I have upload option while writing comment and after submiting comment the file is visable via Wordpress administration.
Comment administration (file is visable at the bottom)
https://i.imgur.com/zIyjy0M.jpg
Custom field settings
https://i.imgur.com/nqNQK5N.png
Code for frontend I'm using in comments template
<?php
$cfile = get_field('comment_file');
if( $cfile ): ?>
<?php echo $cfile['filename']; ?>
<?php endif;
?>
The problem is - I can't see file in frontend part of website. Like there is no file(s).
$comment = get_comment(); // Here you can get single Comment array
$cfile = get_field('comment_file', $comment); // Then you need to pass Comment variable with get_field
if( $cfile ): ?>
<?php echo $cfile['filename']; ?>
<?php endif;
You can visit below link for Reference - https://www.advancedcustomfields.com/resources/get-values-comment/
Disclaimer: If you have never used ACF Flexible Content to build a site, please reserve the hate and all that - looking just for help.
I'm creating a website that's 100% modular, done with Flexible Content.
I have Pages such as:
Home, About, Services, Blog, Portfolio, Contact
All of those pages styled using Flexible Content, these are PAGES.
I have created a custom field for Services and Portfolio, and I used WP Query to display each individal item. These are CUSTOM fields. Show this field group if post type to Services. Not a page.
So when you click it, what happens you go to single-[custom-post-type].php, however I just have single.php to keep it dynamic, which works.
The problem lays that when I have showed the flexible content page templates in the Services or Portfolio, and I add few items, I need go to every single item and set the layout.
How can I do so the layout stays all the same in Service or Portfolio custom field?
Firstly create your ACF Master block, for example, a testimonial section, this would have the repeater fields inside the block etc. In this example, we will call it Testimonial Master.
Then Create another Flexible Content Field Called Testimonial Block with a checkbox that you check to display or hide.
You will now populate Testimonial Master on your selected Parent Page or on an Options page. You then should add the Testimonial Block to any page you are looking to have that block appear on.
You will then went to check that the Testimonial Block is on the page, if it is on the page then you will check if Testimonial Master has a value if it has a value then you can pull in the values from Testimonial Master.
<?php
if( have_rows('page_structure') ):
while ( have_rows('page_structure') ) :
the_row();
if( get_row_layout() == 'testimonial_block' ):
if( get_sub_field('testimonial_block_toggle') == 'show' ):?>
<div class="testimonials">
<?php the_sub_field('testimonial_master_title', 1); ?>
</div>
<?php endif;
endif;
endwhile;
endif;
?>
The "1" is the page ID, use this if you have populated the field on a master page. Or if you are using the ACF Options Page plugin change the "1" to "'options'".
Here is some further documentation on getting values from other posts including that of repeater fields.
https://www.advancedcustomfields.com/resources/how-to-get-values-from-another-post/
Edit: Custom Header as per your example
Make a custom header file and add your code for that header block.
Now make an advanced custom field for a text area. For example header_text_block, set it to a WYSIWYG editor.
Now in your code just use:
<?php the_field('header_text_block');?>
This will then use the exact same header on every page you pull it into, however it will let you edit the text individually for each page.
Edit: Example of what this code looks like and does
Also I think you are very confused, there will only be 1 php/html file? you could use page.php.
Here's an example of what I am saying, 1 php file:
<?php if( have_rows('page_structure') ):
while ( have_rows('page_structure') ) : the_row();
if( get_row_layout() == 'page_featured' ):
$image = get_sub_field('page_featured_image');
if( !empty($image) ):?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>">
<?php endif;
endif;
if( get_row_layout() == 'page_breadcrumbs' ):
if( !in_array( 'hide', get_sub_field('page_breadcrumbs_hide') ) ):?>
<?php if ( function_exists('yoast_breadcrumb') ) {yoast_breadcrumb('<p id="breadcrumbs">','</p>');}?>
<?php else :
endif;
endif;
endwhile;
endif;
?>
This then looks like this on the page editor:
You can then edit each section as you please and also drag and drop sections where you want them which enables easy split testing.
All the styling will be the same, just you can change the content and if you wanted you could add the ability to alter stylings pretty easily. And it only uses 1 PHP file for the template.
I tried following the instruction s but can't get the plugin to work, the fields show in admin and i upload images with them but when I publish and view the post no images show. Do I need to add something to template files for this to show?
Reading from the producer's page they state that for images/files their API returns a URL.
That might mean that the plug-in is not integrated with the native file handling functions. And you might need to use their template tags like <img src="<?php the_field('name') ?>" />.
file: public_html/wp-content/themes/theme_name/category.php
somewhere after this
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<img src="<?php the_field('name') ?>" />
...
Yes, you need to add:
<?php the_field('field_name'); ?>
Check ACF docs: http://www.advancedcustomfields.com/docs/code-examples/
I am working on a drupal 6 site and I am dealing with a views template file which overrides views-view-table.tpl.php. The first few lines of code are:
<table class="<?php print $class; ?>">
<?php if (!empty($title)) : ?>
<caption><?php print $title; ?></caption>
<?php endif; ?>
Where is $title set and what is it? It doesn't seem to be the node id. In the site I am working one, its displaying one of the fields!
It's the title of the View Display (not the machine name of the View!)
See left top corner of the Views Admin UI.
I am building out a site in drupal 7 and running into a ton of problems... very new to drupal here.
I pulled the php call for the logo out of the page.tpl file and put into the header block to be added to all pages. I understand I should probably just leave it in the page.tpl file but thought it made sense to utilize the header block but it is no longer working. can someone explain why this is not working?
here is the code
<div id="logo"><?php if ($logo): ?>
<img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" />
<?php endif; ?></div>
It's because the variable $logo is not available in block.tpl.php, it is provided only to page.tpl.php.
You can actually grab the values yourself like this:
$theme_name = 'name_of_theme';
$settings = variable_get('theme_' . $theme_name . '_settings', array());
if (isset($settings['logo_path'])) {
$logo = file_create_url($settings['logo_path']);
}
all what you need, it's additions in template.php this code
function hook_preprocess_region(&$variables) {
$variables['logo'] = theme_get_setting('logo');
$variables['front_page'] = variable_get('site_frontpage', 'node');
}
clear cache
and $logo and $front_page will works good.