Inside the SPFx web part, how i can get the current site collection url inside the "SharePoint/assets/elements.xml"

john john 946 Reputation points
2021-11-25T19:43:45.823+00:00

I am working on an SPFx web part, which inject a custom css inside the site collection. Now i define the location of the custom css file inside the ClientSideComponentProperties inside the SharePoint/assets/elements.xml file as follow:-

<?xml version="1.0" encoding="utf-8"?>  
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
    <CustomAction  
        Title="InjectCss"  
        Location="ClientSideExtension.ApplicationCustomizer"  
        ClientSideComponentId="5a1fcffd-dfeb-4844-b478-1feb4325a5a7"  
        ClientSideComponentProperties="{&quot;cssurl&quot;:&quot;/sites/Intranet-DEV/customcss/custom.css&quot;}">  
    </CustomAction>  
</Elements>  

152675-sc1.png

so in the above case the custom.css file will be located inside a site collection with this static url https://ourtenat.sharepoint.com/sites/Intranet-DEV/customcss/custom.css.. but can i change the location of the file to be dynamically inside the current site collection (where the web part will be added) ? so on each site collection i will define a library named customcss and add the custom.css file inside it? is this possible?

Thanks

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,859 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,712 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 32,166 Reputation points Microsoft Vendor
    2021-11-26T03:05:26.023+00:00

    Hi @john john ,
    We are unable to set a dynamic value in xml file. There seems no such function to achieve this. We can only set constant value in xml file.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.