page attributes – Remove Header and style.css from Specific Post template

You have to do a couple of things here…

First, you have to create a duplicate of header.php and we’ll name it header-custom-app.php. Now modify the duplicated file and remove the HTML elements you don’t want.

In your template, instead of using get_header(); you would use this:

<?php
/*
 * Template Name: Custom App
 * Template Post Type: post, page, product
 */

 ?>
 <?php get_header( 'custom-app' ); ?>

Having multiple headers, footers and sidebars is acceptable. You can use this exact same method for both get_footer(); and get_sidebar(); if your template needs these or customized versions of these.

Now, for the style.css not being used, I can’t really provide a concrete example because you haven’t provided the code that shows how you currently enqueue it, so what I’m posting here operates on a few assumptions.

Assuming you’re only excluding the style.css from this one template, you could do this:

if( !is_page_template( 'template-custom-app.php' ) ) {
    wp_enqueue_style( 'yourtheme-style', get_stylesheet_uri(), array(), 'x.x' );
}

Obviously change the template-custom-app.php to whatever the name of your template is, change the yourtheme-style and update the x.x to your version number… But what this does is it basically wraps the enqueuing of your style.css in a condition that says ‘if NOT the custom app template, load style.css’.

Alternatively, if your custom app has it’s own CSS stylesheet that it needs you could use:

if( is_page_template( 'template-custom-app.php' ) ) {
    wp_enqueue_style( 'customapp-style', get_stylesheet_directory_uri() . '/css/custom-app.css, array(), 'x.x' );
} else {
    wp_enqueue_style( 'yourtheme-style', get_stylesheet_uri(), array(), 'x.x' );
}

This last snippet assumes you have a css directory in your main theme directory to store secondary CSS files, if it’s just in the root directory then remove the /css from /css/custom-app.css.

magento2 – Embed attributes in Name or Description

I’m trying to work out a way of embedding attributes in other attributes, e.g. name or description in Magento 2.3

As an example

static product name – Blue T-Shirt Size Large

dynamic – {colour_attribute} T-Shirt Size {size_attribute}

{colour_attribute} and {size_attribute} would be separate M2 attributes

I’m not sure it’s possible and I can’t find a module to do it and I wondered if anyone has tried this?

Hope that makes sense.

magento2 – Redirect Simple Products to their Configurable Parent with Attributes Pre-selected

Hey guys I am trying to Redirect Simple Products to their Configurable Parent with Attributes Pre-selected and I followed Daan’s guide. The Observer is as follows:

<?php

namespace DaanvdBRedirectSimpleProductsObserver;

use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;

class Predispatch implements ObserverInterface {

    protected $_redirect;
    protected $_productTypeConfigurable;
    protected $_productRepository;
    protected $_storeManager;

    public function __construct (
        MagentoFrameworkAppResponseHttp $redirect,
        MagentoConfigurableProductModelResourceModelProductTypeConfigurable $productTypeConfigurable,
        MagentoCatalogModelProductRepository $productRepository,
        MagentoStoreModelStoreManagerInterface $storeManager
    ) {
        $this->_redirect = $redirect;
        $this->_productTypeConfigurable = $productTypeConfigurable;
        $this->_productRepository = $productRepository;
        $this->_storeManager = $storeManager;
    }

    public function execute(Observer $observer)
    {
        $pathInfo = $observer->getEvent()->getRequest()->getPathInfo();

        /** If it's not a product view we don't need to do anything. */
        if (strpos($pathInfo, 'product') === false) {
            return;
        }

        $request = $observer->getEvent()->getRequest();
        $simpleProductId = $request->getParam('id');
        if (!$simpleProductId) {
            return;
        }

        $simpleProduct = $this->_productRepository->getById($simpleProductId, false, $this->_storeManager->getStore()->getId());
        if (!$simpleProduct || $simpleProduct->getTypeId() != MagentoCatalogModelProductType::TYPE_SIMPLE) {
            return;
        }

        $configProductId = $this->_productTypeConfigurable->getParentIdsByChild($simpleProductId);
        if (isset($configProductId(0))) {
            $configProduct = $this->_productRepository->getById($configProductId(0), false, $this->_storeManager->getStore()->getId());
            $configType = $configProduct->getTypeInstance();
            $attributes = $configType->getConfigurableAttributesAsArray($configProduct);

            $options = ();
            foreach ($attributes as $attribute) {
                $id = $attribute('attribute_id');
                $value = $simpleProduct->getData($attribute('attribute_code'));
                $options($id) = $value;
            }

            $options = http_build_query($options);
            $hash = $options ? '#' . $options : '';
            $configProductUrl = $configProduct->getUrlModel()
                ->getUrl($configProduct) . $hash;
            $this->_redirect->setRedirect($configProductUrl, 301);
        }
    }
}

Unfortunately, I think a recent Magento update may have broken the code to actually pre-select the attributes. The redirect still works correctly. There were a few other folks have a similar issue on his site. Is there a simple fix we can use to patch this feature? Thanks so much.

php – Where can I find information about input types for product attributes?

I am relatively new to web development, have been using Javascript, HTML and CSS for around 80 hours and now I am getting wet with PHP. I'm sorry if this is a stupid question.

I set up my development environment in Windows with xampp and work with Magento 2.3.5-p1 without the sample data.

I am working on a script that will allow me to import a properly formatted CSV file and convert the data into product attributes that can be applied to different products.

I found the devdocs here programmatically adding product attributes here, but apparently I can't figure out what 'input' => 'types' from the InstallData.php file displayed on this page are valid source and model files that can be used as templates for any input type. Any help on this front would be nice.

Also the database will be fine if the 'type' => 'varchar', always remains varchar, or do inputs such as check boxes have to change the data type to Boolean values?

Below I've attached the progress I've made to give you a better idea of ​​what I want to achieve. You are welcome to make suggestions for improvement, but please ignore the content of $src_content Since I realized that I can't find the information I need to continue.

Before anyone says anything about the security of this script, you should know that this is used on my local computer to automate the creation of over 1300 product attributes It will not go live with the website.

 $_value) {
        $new_item = array();
        foreach ($_value as $key => $value) {
            $new_item( $header($key) ) = $value;
        }

        //creates the folder structure
        $level1folder = array( "modelattribute", "setup", "\etc" );
        $level3folder = array("Backend", "Frontend", "source");
        $level1structure = 'J:xampphtdocsshopappcodevendor\' . $new_item( $header(1)) . '\' . $new_item ( $header(0));
        foreach ($level1folder as $folder) {
            if(!is_dir($level1structure.$folder)){
                mkdir($level1structure.$folder, 0777, true);
                $level3structure = 'J:xampphtdocsshopappcodevendor\' . $new_item( $header(1)) . '\' . $new_item ( $header(0)) . '\modelattribute';
                foreach ( $level3folder as $folder){
                    if(!is_dir($level3structure.$folder)){
                        mkdir($level3structure.$folder, 0777, true);
                    }
                }
            }
        }

        //creates the xml files needed to register the module
        $xml_path_structure ='J:xampphtdocsshopappcodevendor\' . $new_item( $header(1)) . '\' . $new_item ( $header(0)) . '\etc"';
        if (!is_dir($xml_path_structure)) {
            mkdir($xml_path_structure, 0777, true);
        }
        $xml_name = "module.xml";
        $xml_file = fopen($xml_path_structure . $xml_name, "x+") or die("unable to open file!");
       $xml_content =
        '
        
        
         
          
       ';
        fwrite($xml_file, $xml_content);
        fclose($xml_file);

        //creates registration.php and places it in the module's root directory 
        $reg_path_structure ='J:xampphtdocsshopappcodevendor\' . $new_item( $header(1)) . '\' . $new_item ( $header(0)) . '\';
        if (!is_dir($reg_path_structure)) {
            mkdir($reg_path_structure, 0777, true);
        }
        $reg_name = "registration.php";
        $reg_file = fopen($reg_path_structure . $reg_name, "x+") or die("unable to open file!");
        $reg_location = 'vendor_' . $new_item($header (1)) . '_' . $new_item($header(0));
        $reg_content = 
        '   
        eavSetupFactory = $eavSetupFactory;
                }

                /**
                 * {@inheritdoc}
                 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
                 * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
                 * @SuppressWarnings(PHPMD.NPathComplexity)
                 */
                public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
                {
                    $eavSetup = $this->eavSetupFactory->create();
                    $eavSetup->addAttribute(
                        MagentoCatalogModelProduct::ENTITY,
                        ' . $new_item($header(0)) . ",n" .
"                        (n" .
'                              'group' => '' . ($new_item($header(1)) == null ? ''General'' : $new_item($header(1))) . "',n" .
'                              'type' => '' . ($new_item($header(2)) == null ? ''varchar'' : $new_item($header(2))) . "',n" . 
'                              'label' => '' . ($new_item($header(3)) == null ? die("Label cannot be empty!") : $new_item($header(3))) . "',n" .
'                              'input' => '' . ($new_item($header(4)) == null ? die("invalid input type") : $new_item($header(4))) . "',n" .
'                              'source' => '' . 'vendor\' . $new_item( $header(1)). $new_item($header(0)) . 'ModelAttributeSource\' . $new_item($header(0)) . "',n" .
'                              'frontend' => '' . 'vendor\' . $new_item( $header(1)) . $new_item($header(0)) . 'ModelAttributeFrontend\'. $new_item($header(0)) . "',n" .
'                              'backend' => '' . 'vendor\' . $new_item( $header(1)) . $new_item($header(0)) . 'ModelAttributeBackend\'. $new_item($header(0)) . "',n" .
'                              'required' => ' . ($new_item($header(5)) == null ? 'false' : $new_item($header(5))) . ",n" .
'                              'sort_order' => ' . ($new_item($header(6)) == null ? '50' : $new_item($header(6))) . ",n" .
'                              'global' => ' . 'MagentoEavModelEntityAttributeScopedAttributeInterface::SCOPE_' . ($new_item($header(7)) == null ? 'GLOBAL' : $new_item($header(7))) . ",n" .
'                              'is_used_in_grid' => ' . ($new_item($header(8)) == null ? 'false' : $new_item($header(8))) . ",n" .
'                              'is_visible_in_grid' => ' . ($new_item($header(9)) == null ? 'false' : $new_item($header(9))) . ",n" .
'                              'is_filterable_in_grid' => ' . ($new_item($header(10)) == null ? 'false' : $new_item($header(10))) . ",n" .
'                              'visible' => ' . ($new_item($header(11)) == null ? 'true' : $new_item($header(11))) . ",n" .
'                              'is_html_allowed_on_front' => ' . ($new_item($header(12)) == null ? 'true' : $new_item($header(12)) ) . ",n" .
'                              'visible_on_front' => ' . ($new_item($header(13)) == null ? 'true' : $new_item($header(13))) . "n" .
"                        )n" . 
"                   );n" .
"                }n" .
'            }'
        ;
        fwrite($reg_file, $reg_content);
        fclose($reg_file);

        //creates source model and places it in the source folder

        $src_path_structure ='J:xampphtdocsshopappcodevendor\' . $new_item( $header(1)) . '\' . $new_item ( $header(0)) . '\modelattributesource\';
        if (!is_dir($src_path_structure)) {
            mkdir($src_path_structure, 0777, true);
        }
        $src_name = ''' . $new_item( $header(0)) . '.php';
        $src_file = fopen($src_path_structure . $src_name, "x+") or die("unable to open file!");
//        $src_location = 'vendor_' . $new_item($header (1)) . '_' . $new_item($header(0)) . '"setup"';
        $src_content = ($new_item($header(4)) == 'select' ?
        '
        _options) {
                    $this->_options = (
                        ('label' => __('Cotton'), 'value' => 'cotton'),
                        ('label' => __('Leather'), 'value' => 'leather'),
                        ('label' => __('Silk'), 'value' => 'silk'),
                        ('label' => __('Denim'), 'value' => 'denim'),
                        ('label' => __('Fur'), 'value' => 'fur'),
                        ('label' => __('Wool'), 'value' => 'wool'),
                    );
                }
                return $this->_options;
            }
        }

        ' : $new_item($header(4)) == 'checkbox' ? "input template php code here")
        ;

//        fwrite($src_file, $src_content);
//        fclose($src_file);

//    }
    //echo '
'; print_r($_data); echo '

& # 39 ;;
}}

csv_array (& # 39; j: xampp htdocs shop app code guitars.csv & # 39;);

?>

Solving equations – Mathematica has letters that are already defined with certain attributes that cannot be changed?

I want to solve a system of equations to find sixth-order derivatives with finite differences. It is easy for me to define g as a function fi and

a=fi-6
b=fi-5
.
.
g=fi
h=fi+1
i=fi+2
.
.
.
m=fi+6

However, when I use the letters "a" and "h" I have problems

I tried setAttribute [a, Constant] but it doesn't work. I wonder if Mathematica has letters that are already defined with certain attributes that cannot be changed. Thanks a lot

Enter the image description here

8 – How do I change HTML or file removal button attributes?

Standard function for file widgets. File is uploaded, remove button is also added to the page. I am sure the code will run because I can debug it when uploading Ajax. Still no new class, no wrapper element as an answer.

function mytheme_preprocess_file_widget_multiple(&$variables) {
  if ($variables('element')('#field_name') == 'field_my_field') {
    foreach (DrupalCoreRenderElement::children($variables('element')) as $key) {
      $variables('element')($key)('remove_button')('#attributes')('class')() = 'remove-button';
      $variables('element')($key)('remove_button')('#prefix') = '
		Posted on Categories ArticlesTags , , , , , 			

unit – access to object attributes instantiated at runtime after calling start ()

I want to do the following:

void Update()
{
   GameObject gob = Instantiate(Prefab);
   MyContainer comp = gob.GetComponent();
   comp.SetName("something dynamic"); // We'll get an error here
}

The problem is, in the following class, SetName accesses an object that is only instantiated in Start (). The order of events in Unity will not be there MyContainer.Start() is called up to the next frame (see example implementation below).

class MyContainer : MonoBehaviour
{
    TextMeshProUGUI textObj;
    void Start()
    {
        textObj = GetComponentInChildren();
    }
    void SetName(string name)
    {
        // Null Reference Here
        textObj.text = name; // textObj isn't set yet;
    }
}

Is there a recommended / sensible way to deal with objects in such a scenario? I want to prevent too much code on the boiler plate in all my cases MonoBehaviour Subclasses while maintaining a solid separation of concerns.

The options I've been thinking about are:

  1. Use flags:
    a. OnEnable if name is set, set the text
    b. On SetName, if isActiveAndEnabled, set the text
  2. change SetName to a coroutine and paste one yield return null Statement above.
  3. Use similar to 2 Invoke

None of them seem ideal.

  • 1 requires spaghetti-style health checks for each method.
  • 2 requires the return values ​​of methods IEnumerator although nothing is actually meant to be returned.
  • 3 requires an additional method with 0 arguments for each public method and additional status in the MyContainer Class for storing the arguments.